CSIS 10A Assignment 14 SOLUTIONS

Size: px
Start display at page:

Download "CSIS 10A Assignment 14 SOLUTIONS"

Transcription

1 CSIS 10A Assignment 14 SOLUTIONS Read: Chapter 14 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment, then export JAR file and upload to the server using your pass code. You may do more than 10 points of work but the max award will be 11 points. Part I: Exam Prep Exercises-- 7 points total To be answered in the Exercises file Find the Error Problems in the Exercises File 2. public void paint(graphics g) drawline(0, 0, 100, 100); XXXXXX should be g.drawline 4. public class MyPanel extends JPanel XXXXX should be extends JApplet public MyPanel() XXXXX should be public void init() // Constructor code... public void paint(graphics g)

2 // paint method code private class MyMouseListener implements MouseListener public void mouseclicked(mouseevent e) mouseclicks += 1; XXXXXX must have all methods required by the MouseListener interface ( such as mousepressed, mousereleased, mouseentered, mouseexited) Algorithm Workbench a) g.drawrect(50,75,100,200); b) g.fillrect(10,90,300,100); c) g.setcolor(color.blue); g.drawoval(10,25,100,50); d) g.setcolor(color.red); g.drawline(0,5,150,175); e) g.setfont( new Font("Georgia",Font.BOLD,20)); g.drawstring("greetings Earthling"); f) int [] x = 10,10,50,50; int [] y = 10,25,25,10; g.drawpolygon(x,y,4); // it's a rectangle Timer clock = new Timer(500, new MyTimerListener()); Part 2: Programming Challenges 3 points each

3 1) Create a class P1FollowMe that solves the following problem: import java.awt.*; import javax.swing.*; import java.awt.event.*; /** * Class FollowMe - write a description of the class here * Abraham Lopez */ public class P1FollowMe extends JApplet private int currentx = 250; private int currenty = 250; public void init() addmouselistener (new MyMouseListener()); addmousemotionlistener(new MyMouseMotionListener()); public void paint (Graphics g) super.paint(g); g.drawstring ("Hello", currentx, currenty); g.setfont (new Font ("SansSerif", Font.BOLD, 72)); private class MyMouseListener implements MouseListener public void mouseclicked (MouseEvent e) public void mousepressed (MouseEvent e) public void mousereleased (MouseEvent e) public void mouseentered (MouseEvent e) currentx = e.getx(); currenty = e.gety(); repaint (); public void mouseexited (MouseEvent e) currentx = 250; currenty = 250; repaint ();

4 private class MyMouseMotionListener implements MouseMotionListener public void mousedragged(mouseevent e) public void mousemoved(mouseevent e) currentx = e.getx(); currenty = e.gety(); repaint (); 2) Create a class called P2House that solves the following problem: P2House.java import java.awt.*; import javax.swing.*; import java.awt.event.*; /** * Class P2House - write a description of the class here * Abraham Lopez */ public class P2House extends JApplet private boolean dooropen; private boolean rightwindowopen; private boolean leftwindowopen; private int xpos; private int ypos; public void init () dooropen = true;

5 rightwindowopen = true; leftwindowopen = true; addmouselistener (new MyMouseListener()); public void paint (Graphics g) int [] roofx = 50, 250, 450; int [] roofy = 100, 10, 100; super.paint(g); g.drawpolygon (roofx, roofy, 3); g.drawrect (100, 100, 300, 150); g.drawarc (270, 200, 10, 10, 0, 360); if (dooropen) g.fillrect (215, 135, 75, 115); else g.drawrect (215, 135, 75, 115); if (leftwindowopen) g.fillrect (150, 135, 25, 25); g.fillrect (125, 135, 25, 25); g.fillrect (150, 160, 25, 25); g.fillrect (125, 160, 25, 25); else g.drawrect (150, 135, 25, 25); g.drawrect (125, 135, 25, 25); g.drawrect (150, 160, 25, 25); g.drawrect (125, 160, 25, 25); if (rightwindowopen) g.fillrect (350, 135, 25, 25); g.fillrect (325, 135, 25, 25); g.fillrect (350, 160, 25, 25); g.fillrect (325, 160, 25, 25); else g.drawrect (350, 135, 25, 25); g.drawrect (325, 135, 25, 25); g.drawrect (350, 160, 25, 25); g.drawrect (325, 160, 25, 25); private class MyMouseListener extends MouseAdapter public void mousepressed (MouseEvent e)

6 public void mouseclicked (MouseEvent e) xpos = e.getx(); ypos = e.gety(); if ((xpos >= 215 && xpos <= 285) && (ypos >= 135 && ypos <= 250)) dooropen =!dooropen; if ((xpos >= 125 && xpos <= 175) && (ypos >= 135 && ypos <= 185)) leftwindowopen =!leftwindowopen; if ((xpos >= 325 && xpos <= 375) && (ypos >= 135 && ypos <= 185)) rightwindowopen =!rightwindowopen; repaint(); 3) Create a class called P3PolygonDrawer that solves the following problem: import java.awt.*; import javax.swing.*; import java.awt.event.*; /** * Class PolygonDrawer - write a description of the class here * Abraham Lopez */ public class P3PolygonDrawer extends JApplet int count = 0; // keeps track of number of points entered by clicking mouse private int [] xpoints; private int [] ypoints; private int xvalue; private int yvalue; public void init () xpoints = new int [6]; ypoints = new int [6]; addmouselistener (new MyMouseListener ()); public void paint (Graphics g)

7 super.paint(g); g.drawpolygon (xpoints, ypoints, count); private class MyMouseListener extends MouseAdapter public void mouseclicked (MouseEvent e) public void mousepressed (MouseEvent e) xvalue = e.getx(); // save the mouse click point yvalue = e.gety(); if (count < xpoints.length) xpoints[count] = xvalue; // store the point of the mouse click in // the array ypoints[count] = yvalue; count++; // add one to count for next time if (count == xpoints.length) // once we get all the points, repaint repaint(); 4) Create a class called P4GridFiller that solves the following problem: P4GridFiller.java import java.awt.*; import javax.swing.*; import java.awt.event.*; /** * Class P2House - write a description of the class here * Abraham Lopez */ public class P4GridFiller extends JApplet private boolean firstsquare; private boolean secondsquare; private boolean thirdsquare; private boolean fourthsquare; private int xpos; private int ypos; public void init () firstsquare = false;

8 secondsquare = false; thirdsquare = false; fourthsquare = false; addmouselistener (new MyMouseListener()); public void paint (Graphics g) super.paint(g); g.drawrect (100, 100, 100, 100); g.drawrect (200, 100, 100, 100); g.drawrect (100, 200, 100, 100); g.drawrect (200, 200, 100, 100); if (firstsquare) g.setcolor (Color.red); g.fillarc(100, 100, 100, 100, 0, 360); if (secondsquare) g.setcolor (Color.blue); g.fillarc(200, 100, 100, 100, 0, 360); if (thirdsquare) g.setcolor (Color.yellow); g.fillarc(100, 200, 100, 100, 0, 360); if (fourthsquare) g.setcolor (Color.green); g.fillarc(200, 200, 100, 100, 0, 360); private class MyMouseListener extends MouseAdapter public void mousepressed (MouseEvent e) public void mouseclicked (MouseEvent e) xpos = e.getx(); ypos = e.gety(); if ((xpos >= 100 && xpos <= 200) && (ypos >= 100 && ypos <= 200)) firstsquare =!firstsquare; if ((xpos >= 200 && xpos <= 300) && (ypos >= 100 && ypos <= 200)) secondsquare =!secondsquare; if ((xpos >= 100 && xpos <= 200) && (ypos >= 200 && ypos <= 300)) thirdsquare =!thirdsquare; if ((xpos >= 200 && xpos <= 300) && (ypos >= 200 && ypos <= 300))

9 fourthsquare =!fourthsquare; repaint();

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613 OBJECT ORIENTED PROGRAMMING Course 8 Loredana STANCIU loredana.stanciu@upt.ro Room B613 Applets A program written in the Java programming language that can be included in an HTML page A special kind of

More information

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI 51 6!! GUI(Graphical User Interface) java.awt javax.swing (component) GUI... (container) (listener)... MouseListener, ActionLister (adapter)... MouseAdapter, ActionAdapter 6.1 GUI(Graphics User Interface

More information

public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public void mouseclicked (MouseEvent e) int x = e.getx(), y = e.gety();

public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public void mouseclicked (MouseEvent e) int x = e.getx(), y = e.gety(); 11 The Jav aawt Part I: Mouse Events 11.1 public void mouseentered (MouseEvent e) setminute(getminute()+increment); 53 public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public

More information

AP CS Unit 12: Drawing and Mouse Events

AP CS Unit 12: Drawing and Mouse Events AP CS Unit 12: Drawing and Mouse Events A JPanel object can be used as a container for other objects. It can also be used as an object that we can draw on. The first example demonstrates how to do that.

More information

Applet which displays a simulated trackball in the upper half of its window.

Applet which displays a simulated trackball in the upper half of its window. Example: Applet which displays a simulated trackball in the upper half of its window. By dragging the trackball using the mouse, you change its state, given by its x-y position relative to the window boundaries,

More information

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is INDEX Event Handling. Key Event. Methods Of Key Event. Example Of Key Event. Mouse Event. Method Of Mouse Event. Mouse Motion Listener. Example of Mouse Event. Event Handling One of the key concept in

More information

Computer Science II - Test 2

Computer Science II - Test 2 Computer Science II - Test 2 Question 1. (15 points) The MouseListener interface requires methods for mouseclicked, mouseentered, mouseexited, mousepressed, and mousereleased. Java s MouseAdapter implements

More information

Programmierpraktikum

Programmierpraktikum Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 18 17/01/13 11:46 Java Applets 2 of 18 17/01/13 11:46 Java applets embedding Java applications

More information

G51PRG: Introduction to Programming Second semester Applets and graphics

G51PRG: Introduction to Programming Second semester Applets and graphics G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting

More information

CSC System Development with Java Introduction to Java Applets Budditha Hettige

CSC System Development with Java Introduction to Java Applets Budditha Hettige CSC 308 2.0 System Development with Java Introduction to Java Applets Budditha Hettige Department of Statistics and Computer Science What is an applet? applet: a Java program that can be inserted into

More information

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2, Java Mouse Actions C&G criteria: 5.2.1, 5.4.1, 5.4.2, 5.6.2. The events so far have depended on creating Objects and detecting when they receive the event. The position of the mouse on the screen can also

More information

GUI 4.1 GUI GUI MouseTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 1 */

GUI 4.1 GUI GUI MouseTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 1 */ 25 4 GUI GUI GUI 4.1 4.1.1 MouseTest.java /* 1 */ public class MouseTest extends JApplet implements MouseListener /* 2 */ { int x=50, y=20; addmouselistener(this); /* 3 */ super.paint(g); /* 4 */ g.drawstring("hello

More information

AP Computer Science Unit 13. Still More Graphics and Animation.

AP Computer Science Unit 13. Still More Graphics and Animation. AP Computer Science Unit 13. Still More Graphics and Animation. In this unit you ll learn about the following: Mouse Motion Listener Suggestions for designing better graphical programs Simple game with

More information

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More Chapter 14: Applets and More Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 14 discusses the following main topics: Introduction to

More information

Chapter 14: Applets and More

Chapter 14: Applets and More Chapter 14: Applets and More Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 14 discusses the following main topics: Introduction to

More information

Chapter 14: Applets and More

Chapter 14: Applets and More Chapter 14: Applets and More Starting Out with Java: From Control Structures through Objects Fourth Edition by Tony Gaddis Addison Wesley is an imprint of 2010 Pearson Addison-Wesley. All rights reserved.

More information

Some classes and interfaces used in this chapter from Java s original graphics capabilities and from the Java2D API.

Some classes and interfaces used in this chapter from Java s original graphics capabilities and from the Java2D API. CHAPTER 11 513 11 java.lang.object java.awt.color java.awt.component Key class interface java.awt.font java.awt.fontmetrics java.awt.graphics java.awt.polygon Classes and interfaces from the Java2D API

More information

Exam: Applet, Graphics, Events: Mouse, Key, and Focus

Exam: Applet, Graphics, Events: Mouse, Key, and Focus Exam: Applet, Graphics, Events: Mouse, Key, and Focus Name Period A. Vocabulary: Complete the Answer(s) Column. Avoid ambiguous terms such as class, object, component, and container. Term(s) Question(s)

More information

Advanced Java Unit 6: Review of Graphics and Events

Advanced Java Unit 6: Review of Graphics and Events Advanced Java Unit 6: Review of Graphics and Events This is a review of the basics of writing a java program that has a graphical interface. To keep things simple, all of the graphics programs will follow

More information

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a CBOP3203 An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming 1. Event handling in Java 2. Introduction to Java Graphics OOP9 - M. Joldoş - T.U. Cluj 1 Reminder: What is a callback? Callback is a scheme used in event-driven programs where

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST II Date : 20-09-2016 Max Marks: 50 Subject & Code: JAVA & J2EE (10IS752) Section : A & B Name of faculty: Sreenath M V Time : 8.30-10.00 AM Note: Answer all five questions 1) a)

More information

Graphics Applets. By Mr. Dave Clausen

Graphics Applets. By Mr. Dave Clausen Graphics Applets By Mr. Dave Clausen Applets A Java application is a stand-alone program with a main method (like the ones we've seen so far) A Java applet is a program that is intended to transported

More information

Java Applet Basics. Life cycle of an applet:

Java Applet Basics. Life cycle of an applet: Java Applet Basics Applet is a Java program that can be embedded into a web page. It runs inside the web browser and works at client side. Applet is embedded in a HTML page using the APPLET or OBJECT tag

More information

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology: Inheritance 1 Inheritance One class inherits from another if it describes a specialized subset of objects Terminology: the class that inherits is called a child class or subclass the class that is inherited

More information

CS 106A, Lecture 14 Events and Instance Variables

CS 106A, Lecture 14 Events and Instance Variables CS 106A, Lecture 14 Events and Instance Variables Reading: Art & Science of Java, Ch. 10.1-10.4 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons

More information

Lecture 5: Java Graphics

Lecture 5: Java Graphics Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,

More information

CS 106A, Lecture 14 Events and Instance Variables

CS 106A, Lecture 14 Events and Instance Variables CS 106A, Lecture 14 Events and Instance Variables Reading: Art & Science of Java, Ch. 10.1-10.4 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons

More information

Unit 7: Event driven programming

Unit 7: Event driven programming Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Unit 7: Event driven programming 1 1. Introduction 2.

More information

Graphics and Java2D. Objectives

Graphics and Java2D. Objectives jhtp5_12.fm Page 569 Sunday, November 24, 2002 11:59 AM 12 Graphics and Java2D Objectives To understand graphics contexts and graphics objects. To understand and be able to manipulate colors. To understand

More information

Windows and Events. created originally by Brian Bailey

Windows and Events. created originally by Brian Bailey Windows and Events created originally by Brian Bailey Announcements Review next time Midterm next Friday UI Architecture Applications UI Builders and Runtimes Frameworks Toolkits Windowing System Operating

More information

Advanced Internet Programming CSY3020

Advanced Internet Programming CSY3020 Advanced Internet Programming CSY3020 Java Applets The three Java Applet examples produce a very rudimentary drawing applet. An Applet is compiled Java which is normally run within a browser. Java applets

More information

Graphics Applets. By Mr. Dave Clausen

Graphics Applets. By Mr. Dave Clausen Graphics Applets By Mr. Dave Clausen Applets A Java application is a stand-alone program with a main method (like the ones we've seen so far) A Java applet is a program that is intended to transported

More information

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components CS112-Section2 Hakan Guldas Burcin Ozcan Meltem Kaya Muge Celiktas Notes of 6-8 May Graphics Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how

More information

ISO-2022-JP (JIS ) 1 2. (Windows95/98 MacOS ) Java UNICODE UNICODE. Java. .java.java.txt native2ascii. .java

ISO-2022-JP (JIS ) 1 2. (Windows95/98 MacOS ) Java UNICODE UNICODE. Java. .java.java.txt native2ascii. .java 2000 8 2000.1.24-27 0 4 1 ( (1 8 ) ASCII 1 8 1 1 8 2 ISO-2022-JP (JIS ) 1 2 EUC ( EUC) 8 Unix SJIS (MS ) EUC 8 ( (Windows95/98 MacOS Java UNICODE UNICODE ( Java.java.java.txt native2ascii.java native2ascii

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #19: November 4, 2015 1/14 Third Exam The third, Checkpoint Exam, will be on: Wednesday, November 11, 2:30 to 3:45 pm You will have 3 questions, out of 9,

More information

Lecture 3: Java Graphics & Events

Lecture 3: Java Graphics & Events Lecture 3: Java Graphics & Events CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki Text Input Scanner class Constructor: myscanner = new Scanner(System.in); can use file instead of System.in new Scanner(new

More information

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like: OOP Assignment V If we don t use multithreading, or a timer, and update the contents of the applet continuously by calling the repaint() method, the processor has to update frames at a blinding rate. Too

More information

TWO-DIMENSIONAL FIGURES

TWO-DIMENSIONAL FIGURES TWO-DIMENSIONAL FIGURES Two-dimensional (D) figures can be rendered by a graphics context. Here are the Graphics methods for drawing draw common figures: java.awt.graphics Methods to Draw Lines, Rectangles

More information

CS2110. GUIS: Listening to Events

CS2110. GUIS: Listening to Events CS2110. GUIS: Listening to Events Also anonymous classes Download the demo zip file from course website and look at the demos of GUI things: sliders, scroll bars, combobox listener, etc 1 mainbox boardbox

More information

The AWT Event Model 9

The AWT Event Model 9 The AWT Event Model 9 Course Map This module covers the event-based GUI user input mechanism. Getting Started The Java Programming Language Basics Identifiers, Keywords, and Types Expressions and Flow

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Overview

More information

: 15. (x, y) (x, y ) (x, y) ( x x = 1 y = y ) (x = x y y = 1) (12.1.1)

: 15. (x, y) (x, y ) (x, y) ( x x = 1 y = y ) (x = x y y = 1) (12.1.1) 73 12 12.1 15 15 ( 12.1.1) 16 15 15 12.1.1: 15 15 (x, y) x y 0 3 0 0 (x, y ) (x, y) ( x x = 1 y = y ) (x = x y y = 1) (12.1.1) 74 12 Program 12.1.1 Piace.java import java.awt.*; public class Piece { private

More information

cs Java: lecture #5

cs Java: lecture #5 cs3101-003 Java: lecture #5 news: homework #4 due today homework #5 out today today s topics: applets, networks, html graphics, drawing, handling images graphical user interfaces (GUIs) event handling

More information

GUI Event Handling 11. GUI Event Handling. Objectives. What is an Event? Hierarchical Model (JDK1.0) Delegation Model (JDK1.1)

GUI Event Handling 11. GUI Event Handling. Objectives. What is an Event? Hierarchical Model (JDK1.0) Delegation Model (JDK1.1) Objectives Write code to handle events that occur in a GUI 11 GUI Event Handling Describe the concept of adapter classes, including how and when to use them Determine the user action that originated the

More information

1 Definitions & Short Answer (5 Points Each)

1 Definitions & Short Answer (5 Points Each) Fall 2013 Final Exam COSC 117 Name: Write all of your responses on these exam pages. If you need more space please use the backs. Make sure that you show all of your work, answers without supporting work

More information

CS2110. GUIS: Listening to Events. Anonymous functions. Anonymous functions. Anonymous functions. Checkers.java. mainbox

CS2110. GUIS: Listening to Events. Anonymous functions. Anonymous functions. Anonymous functions. Checkers.java. mainbox CS2110. GUIS: Listening to Events Lunch with instructors: Visit pinned Piazza post. A4 due tonight. Consider taking course S/U (if allowed) to relieve stress. Need a letter grade of C- or better to get

More information

CS2110. GUIS: Listening to Events

CS2110. GUIS: Listening to Events CS2110. GUIS: Listening to Events Lunch with instructors: Visit pinned Piazza post. A4 due tonight. Consider taking course S/U (if allowed) to relieve stress. Need a letter grade of C- or better to get

More information

Computer Science 210: Data Structures. Intro to Java Graphics

Computer Science 210: Data Structures. Intro to Java Graphics Computer Science 210: Data Structures Intro to Java Graphics Summary Today GUIs in Java using Swing in-class: a Scribbler program READING: browse Java online Docs, Swing tutorials GUIs in Java Java comes

More information

CS2110. GUIS: Listening to Events Also anonymous classes versus Java 8 functions. Anonymous functions. Anonymous functions. Anonymous functions

CS2110. GUIS: Listening to Events Also anonymous classes versus Java 8 functions. Anonymous functions. Anonymous functions. Anonymous functions CS2110. GUIS: Listening to Events Also anonymous classes versus Java 8 functions Lunch with instructors: Visit Piazza pinned post to reserve a place Download demo zip file from course website, look at

More information

Java - Applets. public class Buttons extends Applet implements ActionListener

Java - Applets. public class Buttons extends Applet implements ActionListener Java - Applets Java code here will not use swing but will support the 1.1 event model. Legacy code from the 1.0 event model will not be used. This code sets up a button to be pushed: import java.applet.*;

More information

Which of the following syntax used to attach an input stream to console?

Which of the following syntax used to attach an input stream to console? Which of the following syntax used to attach an input stream to console? FileReader fr = new FileReader( input.txt ); FileReader fr = new FileReader(FileDescriptor.in); FileReader fr = new FileReader(FileDescriptor);

More information

Görünt Görün ülerin ölçeklenmesi ve yerle y ştirilmesi ş

Görünt Görün ülerin ölçeklenmesi ve yerle y ştirilmesi ş Görüntülerin ölçeklenmesi ve yerleştirilmesi ş Scaled,croped croped and flipped images import java.applet.*; import tjava.awt.*; t* /** An applet that demonstrates image scaling, cropping, and flipping

More information

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development CSCI 053 Introduction to Software Development Rhys Price Jones Week 5 Java is like Alice not based on Joel Adams you may want to take notes Objectives Learn to use the Eclipse IDE Integrated Development

More information

Chapter 1 GUI Applications

Chapter 1 GUI Applications Chapter 1 GUI Applications 1. GUI Applications So far we've seen GUI programs only in the context of Applets. But we can have GUI applications too. A GUI application will not have any of the security limitations

More information

CS 335 Graphics and Multimedia. Image Manipulation

CS 335 Graphics and Multimedia. Image Manipulation CS 335 Graphics and Multimedia Image Manipulation Image Manipulation Independent pixels: image subtraction image averaging grey level mapping thresholding Neighborhoods of pixels: filtering, convolution,

More information

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain

More information

Assignment 8B SOLUTIONS

Assignment 8B SOLUTIONS CSIS 10A Assignment 8B SOLUTIONS Read: Chapter 8 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

More information

Java Coordinate System

Java Coordinate System Java Graphics Drawing shapes in Java such as lines, rectangles, 3-D rectangles, a bar chart, or a clock utilize the Graphics class Drawing Strings Drawing Lines Drawing Rectangles Drawing Ovals Drawing

More information

Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,

Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1, Java - Applets C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1, 5.3.2. Java is not confined to a DOS environment. It can run with buttons and boxes in a Windows

More information

Java for Interfaces and Networks (DT3010, HT10)

Java for Interfaces and Networks (DT3010, HT10) Java for Interfaces and Networks (DT3010, HT10) Mouse Events, Timers, Serialization Federico Pecora School of Science and Technology Örebro University federico.pecora@oru.se Federico Pecora Java for Interfaces

More information

Advanced Java Programming

Advanced Java Programming Advanced Java Programming Shmulik London Lecture #5 GUI Programming Part I AWT & Basics Advanced Java Programming / Shmulik London 2006 Interdisciplinary Center Herzeliza Israel 1 Agenda AWT & Swing AWT

More information

EXCEPTIONS & GUI. Errors are signals that things are beyond help. Review Session for. -Ankur Agarwal

EXCEPTIONS & GUI. Errors are signals that things are beyond help. Review Session for. -Ankur Agarwal Review Session for EXCEPTIONS & GUI -Ankur Agarwal An Exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. Errors are signals

More information

FirstSwingFrame.java Page 1 of 1

FirstSwingFrame.java Page 1 of 1 FirstSwingFrame.java Page 1 of 1 2: * A first example of using Swing. A JFrame is created with 3: * a label and buttons (which don t yet respond to events). 4: * 5: * @author Andrew Vardy 6: */ 7: import

More information

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM Introduction to the Assignment In this assignment, you will get practice with recursion. There are three parts

More information

CIS 162 Project 1 Business Card Section 04 (Kurmas)

CIS 162 Project 1 Business Card Section 04 (Kurmas) CIS 162 Project 1 Business Card Section 04 (Kurmas) Due Date at the start of lab on Monday, 17 September (be prepared to demo in lab) Before Starting the Project Read zybook chapter 1 and 3 Know how to

More information

I/O Framework and Case Study. CS151 Chris Pollett Nov. 2, 2005.

I/O Framework and Case Study. CS151 Chris Pollett Nov. 2, 2005. I/O Framework and Case Study CS151 Chris Pollett Nov. 2, 2005. Outline Character Streams Random Access Files Design case study Planning Iterations Character Streams Java internally represents strings as

More information

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4. 1 - What if the main method is declared as private? 1. The program does not compile 2. The program compiles but does not run 3. The program compiles and runs properly ( From Lectuer # 2) 4. The program

More information

at 1.000,5.289 ljust "JLabel" at 3.438,5.289 ljust " JPanel" at 2.125,6.914 ljust "JFrame" at 2.250,9.039 ljust "content pane" at 2.125,7.

at 1.000,5.289 ljust JLabel at 3.438,5.289 ljust  JPanel at 2.125,6.914 ljust JFrame at 2.250,9.039 ljust content pane at 2.125,7. 1. Painting When a Swing GUI needs to paint itself -- whether for the first time, in response to becoming unhidden, or because it needs to reflect a change in the program s state -- it starts with the

More information

9. APPLETS AND APPLICATIONS

9. APPLETS AND APPLICATIONS 9. APPLETS AND APPLICATIONS JAVA PROGRAMMING(2350703) The Applet class What is an Applet? An applet is a Java program that embedded with web content(html) and runs in a Web browser. It runs inside the

More information

CSIS 10A Assignment 7 SOLUTIONS

CSIS 10A Assignment 7 SOLUTIONS CSIS 10A Assignment 7 SOLUTIONS Read: Chapter 7 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

More information

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming

More information

File: GFace.java /* * File: GFace.java * This class implements a face as a GCompound. */

File: GFace.java /* * File: GFace.java * This class implements a face as a GCompound. */ Steve Cooper Handout #22 CS 106A April 24, 2013 Graphics and Events Examples File: GFace.java * File: GFace.java * This class implements a face as a GCompound. // Note: only need acm.graphics since this

More information

Graphic User Interfaces. - GUI concepts - Swing - AWT

Graphic User Interfaces. - GUI concepts - Swing - AWT Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations

More information

CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed

CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What would

More information

Event Driven Programming

Event Driven Programming Event Driven Programming 1. Objectives... 2 2. Definitions... 2 3. Event-Driven Style of Programming... 2 4. Event Polling Model... 3 5. Java's Event Delegation Model... 5 6. How to Implement an Event

More information

Fall 2011 Final Test

Fall 2011 Final Test 60-212 Fall 2011 Final Test Answer all questions You are allowed to bring in one unmarked textbook on Java and the 60-212 lecture slides (unmarked). No other material will be allowed. This test has 11

More information

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday!

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday! Lab & Assignment 1 Lecture 3: ArrayList & Standard Java Graphics CS 62 Fall 2015 Kim Bruce & Michael Bannister Strip with 12 squares & 5 silver dollars placed randomly on the board. Move silver dollars

More information

Events Chris Piech CS106A, Stanford University. Piech, CS106A, Stanford University

Events Chris Piech CS106A, Stanford University. Piech, CS106A, Stanford University Events Chris Piech CS106A, Stanford University Catch Me If You Can We ve Gotten Ahead of Ourselves Source: The Hobbit Start at the Beginning Source: The Hobbit Learning Goals 1. Write a program that can

More information

Yvon s Checker game: Begin Board class

Yvon s Checker game: Begin Board class Yvon s Checker game: Begin Board class Board extends JPanel - This class creates the Frame by extending JPanel. A checker Board is created in the panel. Relationship: Board is a JPanel, Board has a Square,

More information

THE UNIVERSITY OF AUCKLAND

THE UNIVERSITY OF AUCKLAND CompSci 101 with answers THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2012 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: You must answer all questions in this test.

More information

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners GUI (Graphic User Interface) Programming Part 2 (Chapter 8) Chapter Goals To understand the Java event model To install action and mouse event listeners To accept input from buttons, text fields, and the

More information

Side Trip into Java: Enumeration Types. CS61B Lecture #36. Making Enumerals Available Elsewhere. Enum Types in Java. import static checkers.piece.

Side Trip into Java: Enumeration Types. CS61B Lecture #36. Making Enumerals Available Elsewhere. Enum Types in Java. import static checkers.piece. CS61B Lecture #36 Today: A Brief Side Trip: Enumeration types. DSIJ, Chapter 10, HFJ, pp. 489 516. Threads Communication between threads Synchronization es Coming Up: Graph Structures: DSIJ, Chapter 12

More information

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events Objectives Event Handling Animation Discussion of Roulette Assignment How easy/difficult to refactor for extensibility? Was it easier to add to your refactored code? Ø What would your refactored classes

More information

Dr. Hikmat A. M. AbdelJaber

Dr. Hikmat A. M. AbdelJaber Dr. Hikmat A. M. AbdelJaber Portion of the Java class hierarchy that include basic graphics classes and Java 2D API classes and interfaces. java.lang.object Java.awt.Color Java.awt.Component Java.awt.Container

More information

User interfaces and Swing

User interfaces and Swing User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. CSIS 10A PRACTICE FINAL EXAM SOLUTIONS Closed Book Closed Computer 3 Sheets of Notes Allowed MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What

More information

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { }

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { } CBOP3203 What Is an Event? Events Objects that describe what happened Event Sources The generator of an event Event Handlers A method that receives an event object, deciphers it, and processes the user

More information

CSIS 10A Practice Final Exam Solutions

CSIS 10A Practice Final Exam Solutions CSIS 10A Practice Final Exam Solutions 1) (5 points) What would be the output when the following code block executes? int a=3, b=8, c=2; if (a < b && b < c) b = b + 2; if ( b > 5 a < 3) a = a 1; if ( c!=

More information

Chapter 1 Introduction to Java

Chapter 1 Introduction to Java Chapter 1 Introduction to Java Lesson page 0-1. Introduction to Livetexts Question 1. A livetext is a text that relies not only on the printed word but also on graphics, animation, audio, the computer,

More information

Programming graphics

Programming graphics Programming graphics Need a window javax.swing.jframe Several essential steps to use (necessary plumbing ): Set the size width and height in pixels Set a title (optional), and a close operation Make it

More information

Chapter 12 Advanced GUIs and Graphics

Chapter 12 Advanced GUIs and Graphics Chapter 12 Advanced GUIs and Graphics Chapter Objectives Learn about applets Explore the class Graphics Learn about the classfont Explore the classcolor Java Programming: From Problem Analysis to Program

More information

China Jiliang University Java. Programming in Java. Java Applets. Java Web Applications, Helmut Dispert

China Jiliang University Java. Programming in Java. Java Applets. Java Web Applications, Helmut Dispert Java Programming in Java Java Applets Java Applets applet = app = application snippet = (German: Anwendungsschnipsel) An applet is a small program that is intended not to be run on its own, but rather

More information

Chapter 7 Applets. Answers

Chapter 7 Applets. Answers Chapter 7 Applets Answers 1. D The drawoval(x, y, width, height) method of graphics draws an empty oval within a bounding box, and accepts 4 int parameters. The x and y coordinates of the left/top point

More information

Come & Join Us at VUSTUDENTS.net

Come & Join Us at VUSTUDENTS.net Come & Join Us at VUSTUDENTS.net For Assignment Solution, GDB, Online Quizzes, Helping Study material, Past Solved Papers, Solved MCQs, Current Papers, E-Books & more. Go to http://www.vustudents.net and

More information

HW#1: Pencil Me In Status!? How was Homework #1? Reminder: Handouts. Homework #2: Java Draw Demo. 3 Handout for today! Lecture-Homework mapping.

HW#1: Pencil Me In Status!? How was Homework #1? Reminder: Handouts. Homework #2: Java Draw Demo. 3 Handout for today! Lecture-Homework mapping. HW#1: Pencil Me In Status!? CS193J: Programming in Java Summer Quarter 2003 Lecture 6 Inner Classes, Listeners, Repaint Manu Kumar sneaker@stanford.edu How was Homework #1? Comments please? SITN students

More information

Contents. 18 Algorithms Case study: network search The search algorithm Case study: automatic language recognition 57

Contents. 18 Algorithms Case study: network search The search algorithm Case study: automatic language recognition 57 0 Contents 17 Object oriented design 1 17.1 Abstract classes and interfaces 1 17.2 Collections 5 17.3 Extensions of AWT 11 17.4 Application: a sketch program 15 17.5 File input/output 33 17.6 Non-window

More information

Appendix G Navigation and Collision Detection for Web-Based 3D Experiment

Appendix G Navigation and Collision Detection for Web-Based 3D Experiment Appendix G Appendix G Navigation and Collision Detection for Web-Based 3D Experiment G.1 ImportInG libraries import javax.media.j3d.*; import javax.vecmath.*; import java.awt.event.*; import java.awt.awtevent;

More information

SIMPLE APPLET PROGRAM

SIMPLE APPLET PROGRAM APPLETS Applets are small applications that are accessed on Internet Server, transported over Internet, automatically installed and run as a part of web- browser Applet Basics : - All applets are subclasses

More information

Advanced Java Programming (17625) Event Handling. 20 Marks

Advanced Java Programming (17625) Event Handling. 20 Marks Advanced Java Programming (17625) Event Handling 20 Marks Specific Objectives To write event driven programs using the delegation event model. To write programs using adapter classes & the inner classes.

More information