Java for Interfaces and Networks (DT3010, HT10)

Size: px
Start display at page:

Download "Java for Interfaces and Networks (DT3010, HT10)"

Transcription

1 Java for Interfaces and Networks (DT3010, HT10) Mouse Events, Timers, Serialization Federico Pecora School of Science and Technology Örebro University Federico Pecora Java for Interfaces and Networks Lecture 11 1 / 21

2 Outline 1 Mouse Events 2 Timers 3 Serialization Federico Pecora Java for Interfaces and Networks Lecture 11 2 / 21

3 Mouse Events Outline 1 Mouse Events 2 Timers 3 Serialization Federico Pecora Java for Interfaces and Networks Lecture 11 3 / 21

4 Mouse Events Listening to Mouse Events Java provides a number of classes and interfaces for listening to mouse events, among which interface MouseMotionListener: listens to mouse motion events (moving, dragging), can track precise motion of the mouse interface MouseWheelListener: provides listener for wheel events (e.g., scrolling down a scrollbar with mouse wheel) class MouseListener: listens to mouse clicking and hover events Also, some adapter classes are provided (i.e., eliminating the need to implement each method of the interface), among which class MouseAdapter: provides default implementation of all three interfaces Federico Pecora Java for Interfaces and Networks Lecture 11 4 / 21

5 Mouse Events Interfaces MouseListener and MouseMotionListener public interface MouseListener extends EventListener { public void mousepressed(mouseevent e); public void mousereleased(mouseevent e); public void mouseclicked(mouseevent e); public void mouseentered(mouseevent e); public void mouseexited(mouseevent e); } public interface MouseMotionListener extends EventListener { public void mousedragged(mouseevent e); public void mousemoved(mouseevent e); } Federico Pecora Java for Interfaces and Networks Lecture 11 5 / 21

6 Mouse Events Interfaces MouseListener and MouseMotionListener mousepressed() occurs when the user presses the mouse button mousereleased() occurs when the user releases the mouse button mouseclicked() occurs when the user presses and releases the mouse button (double click is two mouse clicks in succession) mousepressed() and mousereleased() methods are both called first mouseentered()/mouseexited() occurs when the mouse enters/leaves the component you are listening to Federico Pecora Java for Interfaces and Networks Lecture 11 6 / 21

7 Mouse Events Interfaces MouseListener and MouseMotionListener mousedragged() occurs when the user presses the mouse button and moves the mouse before releasing the button does not trigger mouseclicked() mousepressed() and mousereleased() methods are both called does not trigger mousemoved() mousemoved() occurs when the mouse moves within the component without being dragged Federico Pecora Java for Interfaces and Networks Lecture 11 7 / 21

8 Mouse Events Interface MouseMotionListener: example An application with two simple components over which we listen to mouse events and log them in a text area Federico Pecora Java for Interfaces and Networks Lecture 11 8 / 21

9 Mouse Events Interface MouseMotionListener: example First, let s make a BlankArea class (an extension of JPanel) which we will for making test components BlankArea.java 1 class BlankArea extends JPanel { 2 final Dimension mysize = new Dimension(100, 100); 3 public BlankArea() { 4 setbackground(new Color(0.98f, 0.97f, 0.85f)); 5 setborder(new LineBorder(Color.green, 2)); 6 } 7 public Dimension getpreferredsize() { return mysize; } 8 public Dimension getminimumsize() { return mysize; } 9 } // class BlankArea Federico Pecora Java for Interfaces and Networks Lecture 11 8 / 21

10 Mouse Events Interface MouseMotionListener: example Now let s put two BlankAreas in a JPanel, together with a JTextArea to see the mouse events, and instantiate the listeners Mousepanel.java 1 class Mousepanel extends JPanel { 2 public Mousepanel() { 3 super(new FlowLayout()); 4 JPanel blankpanel1 = new JPanel(); 5 blankpanel1.setbackground(new Color(0.98f, 0.97f, 0.85f)); 6 Dimension size = new Dimension(100, 100); 7 blankpanel1.setpreferredsize(size); 8 blankpanel1.setminimumsize(size); 9 blankpanel1.setborder(new LineBorder(Color.red, 2)); 10 add(blankpanel1); 11 BlankArea blankpanel2 = new BlankArea(); 12 add(blankpanel2); 13 //... Federico Pecora Java for Interfaces and Networks Lecture 11 8 / 21

11 Mouse Events Interface MouseMotionListener: example Now let s put two BlankAreas in a JPanel, together with a JTextArea to see the mouse events, and instantiate the listeners Mousepanel.java (cont.) 14 JTextArea textarea = new JTextArea(); 15 textarea.seteditable(false); 16 JScrollPane scrollpane = new JScrollPane(textarea, 17 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 18 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 19 scrollpane.setpreferredsize(new Dimension(300, 75)); 20 add(scrollpane); 21 MyListener lyssnare = new MyListener(textarea); 22 blankpanel1.addmousemotionlistener(lyssnare); 23 blankpanel2.addmousemotionlistener(lyssnare); 24 setpreferredsize(new Dimension(400, 200)); 25 } //MousePanel 26 //... Federico Pecora Java for Interfaces and Networks Lecture 11 8 / 21

12 Mouse Events Interface MouseMotionListener: example At this point we define the mouse motion listener Mousepanel.java (cont.) 27 private class MyListener implements MouseMotionListener { 28 private JTextArea textarea; 29 public MyListener(JTextArea ta) { textarea = ta; } 30 public void mousemoved(mouseevent e) { 31 log("moving", e); 32 } 33 public void mousedragged(mouseevent e) { 34 log("dragging", e); 35 } 36 //... Federico Pecora Java for Interfaces and Networks Lecture 11 8 / 21

13 Mouse Events Interface MouseMotionListener: example At this point we define the mouse motion listener Mousepanel.java (cont.) 37 private void log(string eventdescription, MouseEvent e) { 38 textarea.append(eventdescription + 39 " (" + e.getx() + "," + e.gety() + ")" + 40 " in " + 41 e.getcomponent().getclass().getname() + "\n"); 42 textarea.setcaretposition( 43 textarea.getdocument().getlength()); 44 } 45 } //class MyListener 46 } //class MousePanel Federico Pecora Java for Interfaces and Networks Lecture 11 8 / 21

14 Mouse Events Interface MouseMotionListener: example Finally, the JFrame... MouseWindow.java 1 class MouseWindow extends JFrame { 2 public MouseWindow() { 3 super("mousemotionlistener Demo"); 4 getcontentpane().add(new Mousepanel()); 5 pack(); 6 } 7 public static void main(string[] args) { 8 MouseWindow m = new MouseWindow(); 9 m.setdefaultcloseoperation(jframe.exit_on_close); 10 m.setvisible(true); 11 } 12 } //class MouseWindow Federico Pecora Java for Interfaces and Networks Lecture 11 8 / 21

15 Mouse Events Interface MouseListener: example Now we want a listener that can react to mouse clicks We can implement the MouseListener interface in addition to the MouseMotionListener interface... Federico Pecora Java for Interfaces and Networks Lecture 11 9 / 21

16 Mouse Events Interface MouseListener: example Instantiating the new listener Mousepanel.java (cont.) 14 // MyListener lyssnare = new MyListener(textarea); 16 blankpanel1.addmousemotionlistener(lyssnare); 17 blankpanel2.addmousemotionlistener(lyssnare); 18 MyListener2 lyssnare2 = new MyListener2(textarea); 19 blankpanel1.addmouselistener(lyssnare2); 20 blankpanel2.addmouselistener(lyssnare2); 21 //... Federico Pecora Java for Interfaces and Networks Lecture 11 9 / 21

17 Mouse Events Interface MouseListener: example Defining the new listener Mousepanel.java (cont.) 27 private class MyListener2 implements MouseListener { 28 private JTextArea textarea; 29 public MyListener2(JTextArea ta) { textarea = ta; } 30 public void mousepressed(mouseevent e) { 31 log("mouse pressed; num clicks = " + 32 e.getclickcount(), e); 33 } 34 public void mousereleased(mouseevent e) { 35 log("mouse released; num clicks = " + 36 e.getclickcount(), e); 37 } 38 public void mouseentered(mouseevent e) { 39 log("mouse enters", e); 40 } Federico Pecora Java for Interfaces and Networks Lecture 11 9 / 21

18 Mouse Events Interface MouseListener: example Defining the new listener Mousepanel.java (cont.) 41 public void mouseexited(mouseevent e) { 42 log("mouse exits", e); 43 } 44 public void mouseclicked(mouseevent e) { 45 log("mouse clicked; num clicks = " + 46 e.getclickcount(), e); 47 } 48 private void log(string eventdescription, MouseEvent e) { 49 textarea.append(eventdescription + 50 " (" + e.getx() + "," + e.gety() + ")" + 51 " in " + 52 e.getcomponent().getclass().getname() + "\n"); 53 textarea.setcaretposition( 54 textarea.getdocument().getlength()); 55 } 56 } //class MyListener2 Federico Pecora Java for Interfaces and Networks Lecture 11 9 / 21

19 Mouse Events Interface MouseAdapter: example Our two listeners are long because the have to implement all methods of the interfaces MouseMotionListener and MouseListener If we do not need all mouse events, we can extend the abstract class MouseAdapter Federico Pecora Java for Interfaces and Networks Lecture / 21

20 Mouse Events Interface MouseAdapter: example Mousepanel.java (cont.) 14 private class MyListener3 extends MouseAdapter 15 implements MouseListener { 16 private JTextArea textarea; 17 public MyListener3(JTextArea ta) { textarea = ta; } 18 public void mouseclicked(mouseevent e) { 19 log("mouse click; num clicks = " + 20 e.getclickcount(), e); 21 } 22 private void log(string eventdescription, MouseEvent e) { 23 textarea.append(eventdescription + 24 " (" + e.getx() + "," + e.gety() + ")" + 25 " in " + 26 e.getcomponent().getclass().getname() + "\n"); 27 textarea.setcaretposition( 28 textarea.getdocument().getlength()); 29 } 30 } //class MyListener3 31 //... Federico Pecora Java for Interfaces and Networks Lecture / 21

21 Timers Outline 1 Mouse Events 2 Timers 3 Serialization Federico Pecora Java for Interfaces and Networks Lecture / 21

22 Timers High-level thread support As we saw in the previous lecture, Java offers a number of facilitations for building multi-threaded GUIs As of Java 1.3, there exists the class java.util.timer used to perform tasks repeatedly or after a delay There exists also javax.swing.timer, a similar class which is dedicated to GUI support facilitates developing repeating/delayed tasks which need to update the GUI separates the actual waiting from the event dispatch thread Federico Pecora Java for Interfaces and Networks Lecture / 21

23 Timers java.util.timer example Presenter.java (cont.) 20 public static void main(string[] args) { 21 Presenter t1 = new Presenter("FirstThread", 0.1); 22 Presenter t2 = new Presenter("SecondThread", 0.2); 23 Presenter t3 = new Presenter("ThirdThread", 0.3); 24 } //main 25 } //class Presenter <-- IMPLEMENTED IN LEC. 4 linux> java Presenter FirstThread SecondThread ThirdThread FirstThread SecondThread FirstThread ThirdThread FirstThread SecondThread FirstThread FirstThread ThirdThread SecondThread FirstThread FirstThread SecondThread FirstThread ThirdThread FirstThread SecondThread FirstThread FirstThread ThirdThread SecondThread FirstThread FirstThread SecondThread Federico Pecora Java for Interfaces and Networks Lecture / 21

24 Timers java.util.timer example In the version implemented in lecture 4, it was possible that the threads were not synchronized linux> java Presenter... FirstThread... ThirdThread SecondThread SecondThread FirstThread FirstThread FirstThread SecondThread java.util.timer and its companion class java.util.timertask provide a way to overcome this easily! Federico Pecora Java for Interfaces and Networks Lecture / 21

25 Timers java.util.timer example PresenterTask.java 1 public class PresenterTask extends TimerTask { 2 private String message; 3 private double sleeptime; 4 private int steps; 5 public PresenterTask(String message, double sleeptime) { 6 this.message = message; 7 this.sleeptime = sleeptime; 8 this.steps = 0; 9 Timer timer = new Timer(); 10 timer.schedule(this, 0, (int)(sleeptime * 1000)); 11 } 12 //... Federico Pecora Java for Interfaces and Networks Lecture / 21

26 Timers java.util.timer example PresenterTask.java (cont.) 12 public void run() { 13 for (int i = 0; i < this.steps; ++i) 14 System.out.print(" "); 15 ++this.steps; 16 System.out.println(this.message); 17 } //run 18 public static void main(string[] args) { 19 PresenterTask t1 = new PresenterTask("FirstThread", 0.1); 20 PresenterTask t2 = new PresenterTask("SecondThread", 0.2); 21 PresenterTask t3 = new PresenterTask("ThirdThread", 0.3); 22 } //main 23 } //class PresenterTask Federico Pecora Java for Interfaces and Networks Lecture / 21

27 Timers java.util.timer example Instantiate a java.util.timer Extend java.util.timertask this class looks a lot like a thread, in that it has a run() method schedule() one or more instances of your TimerTasks on the Timer NB: each Timer object is a single background thread that is used to execute all of the timer s tasks, sequentially so actually we are not running three threads anymore! NB: TimerTasks should complete quickly, and Timer does not offer real-time guarantees Federico Pecora Java for Interfaces and Networks Lecture / 21

28 Timers Timers in Swing The class javax.swing.timer offers similar functionality, but tailored to the needs of GUI development The purpose of this class is to fire one or more ActionEvents after a specified delay e.g., used to animate components To set up a javax.swing.timer you create a javax.swing.timer object register one or more ActionListeners on it start the timer using the start() method Federico Pecora Java for Interfaces and Networks Lecture / 21

29 Timers Timers in Swing Setting up a javax.swing.timer 1 int delay = 1000; //milliseconds 2 ActionListener taskperformer = new ActionListener() { 3 public void actionperformed(actionevent evt) { 4 //Define task to perform... 5 } 6 }; 7 new Timer(delay, taskperformer).start(); Like java.util.timers, also javax.swing.timers perform their waiting using a single, shared thread However, the action event handlers for javax.swing.timers execute on the event dispatch thread Therefore it is safe to perform operations on Swing components... but they must end quickly! Federico Pecora Java for Interfaces and Networks Lecture / 21

30 Serialization Outline 1 Mouse Events 2 Timers 3 Serialization Federico Pecora Java for Interfaces and Networks Lecture / 21

31 Serialization What is serialization? Can object instances exist outside the JVM? Object serialization provides a means to flatten your objects for storage/transport outside the running JVM can make persistent object instances provides stream mechanism for writing and reading object instances Not all classes are serializable, only those that implement the interface Serializable this does not include Thread, Socket, but does include a large number of other classes, including Swing components Federico Pecora Java for Interfaces and Networks Lecture / 21

32 Serialization Serialization: example Let s make a simple class that is serializable Data.java 1 class Data implements Serializable { 2 private int n; 3 public Data(int n) { this.n = n; } 4 public String tostring() { return Integer.toString(n); } 5 } //class Data Federico Pecora Java for Interfaces and Networks Lecture / 21

33 Serialization Serialization: example Let s instantiate some Data objects and output them to a file... SerializationTest.java 1 public class SerializationTest { 2 public static void main(string[] args) 3 throws ClassNotFoundException, IOException { 4 Data d1 = new Data(17); 5 Data d2 = new Data(4711); 6 Data d3 = new Data(7); 7 ObjectOutputStream out = 8 new ObjectOutputStream( 9 new FileOutputStream("data.out")); 10 out.writeobject(d1); 11 out.writeobject(d2); 12 out.writeobject(d3); 13 out.close(); // Also flushes output 14 }//main 15 }// class SerializationTest Federico Pecora Java for Interfaces and Networks Lecture / 21

34 Serialization Serialization: example The three objects instances are stored in the binary file data.out (53 bytes long) linux> more data.out Federico Pecora Java for Interfaces and Networks Lecture / 21

35 Serialization Serialization: example Let s read the instances back in form the file... SerializationTest.java (cont.) 15 ObjectInputStream in = 16 new ObjectInputStream( 17 new FileInputStream("data.out")); 18 Data d4 = (Data)in.readObject(); 19 Data d5 = (Data)in.readObject(); 20 Data d6 = (Data)in.readObject(); 21 System.out.println("d1 = " + d1); 22 System.out.println("d2 = " + d2); 23 System.out.println("d3 = " + d3); 24 System.out.println("d4 = " + d4); 25 System.out.println("d5 = " + d5); 26 System.out.println("d6 = " + d6); 27 }//main 28 }// class SerializationTest Federico Pecora Java for Interfaces and Networks Lecture / 21

36 Serialization Serialization: example Let s read the instances back in form the file... linux> java SerializationTest d1 = 17 d2 = 4711 d3 = 7 d4 = 17 d5 = 4711 d6 = 7 Federico Pecora Java for Interfaces and Networks Lecture / 21

37 Serialization Serialization: example Notice that we could take advantage of Java s late binding to invoke the appropriate method (i.e., avoid cast to Data class) SerializationTest.java (cont.) 15 ObjectInputStream in = 16 new ObjectInputStream( 17 new FileInputStream("data.out")); 18 Data d4 = (Data)in.readObject(); 19 Data d5 = (Data)in.readObject(); 20 Object d6 = in.readobject(); 21 System.out.println("d1 = " + d1); 22 System.out.println("d2 = " + d2); 23 System.out.println("d3 = " + d3); 24 System.out.println("d4 = " + d4); 25 System.out.println("d5 = " + d5); 26 System.out.println("d6 = " + d6); 27 //... Federico Pecora Java for Interfaces and Networks Lecture / 21

38 Serialization Serialization: example Late binding ensures that the method Data.toString() is invokes instead of Object.toString() linux> java SerializationTest d1 = 17 d2 = 4711 d3 = 7 d4 = 17 d5 = 4711 d6 = 7 Federico Pecora Java for Interfaces and Networks Lecture / 21

39 Serialization Serialization: transient Notice that instead of a FileOutputStream, we could have given a Socket s output stream Now, what if we have members of our serializable class that are not serializable? We can mark these members as transient allows to mark members as excluded from the serialization Federico Pecora Java for Interfaces and Networks Lecture / 21

40 Serialization Serialization: transient Marking Thread member as transient PersistentAnimation.java 1 public class PersistentAnimation 2 implements Serializable, Runnable { 3 transient private Thread animator; 4 private int animationspeed; 5 public PersistentAnimation(int animationspeed) { 6 this.animationspeed = animationspeed; 7 animator = new Thread(this); 8 animator.start(); 9 } 10 public void run() { /* do animation */ } 11 } Federico Pecora Java for Interfaces and Networks Lecture / 21

41 Serialization Serialization: transient Marking Thread member as transient PersistentAnimation.java 1 public class PersistentAnimation 2 implements Serializable, Runnable { 3 transient private Thread animator; 4 private int animationspeed; 5 public PersistentAnimation(int animationspeed) { 6 this.animationspeed = animationspeed; 7 animator = new Thread(this); 8 animator.start(); 9 } 10 public void run() { /* do animation */ } 11 } However, the reloaded PersistentAnimation will not work! This is because the constructor is not re-invoked Federico Pecora Java for Interfaces and Networks Lecture / 21

42 Serialization Serialization: transient To overcome this limitation, we modify the protocol by implementing writeobject() and readobject() PersistentAnimation.java 1 public class PersistentAnimation 2 implements Serializable, Runnable { 3 transient private Thread animator; 4 private int animationspeed; 5 public PersistentAnimation(int animationspeed) { 6 this.animationspeed = animationspeed; 7 startanimation(); 8 } 9 public void run() { /* do animation */ } 10 private void writeobject(objectoutputstream out) 11 throws IOException { 12 out.defaultwriteobject(); 13 } 14 //... Federico Pecora Java for Interfaces and Networks Lecture / 21

43 Serialization Serialization: transient To overcome this limitation, we modify the protocol by implementing writeobject() and readobject() PersistentAnimation.java (cont.) 15 private void readobject(objectinputstream in) 16 throws IOException, ClassNotFoundException { 17 in.defaultreadobject(); 18 startanimation(); 19 } 20 private void startanimation() { 21 animator = new Thread(this); 22 animator.start(); 23 } 24 } Federico Pecora Java for Interfaces and Networks Lecture / 21

44 Serialization Serialization: transient The two methods writeobject() and readobject() are private neither method is inherited and overridden or overloaded This solution allows to avoid that whoever is de-serializing does not have to invoke some ad-hoc method to properly re-create the object Overview of workflow 1 implement interface Serializable 2 mark non-serializable fields as transient 3 provide writeobject() and readobject() methods if there is any additional operation to be performed upon serialization/de-serialization Federico Pecora Java for Interfaces and Networks Lecture / 21

45 Serialization Mouse Events, Timers, Serialization Thank you! Federico Pecora Java for Interfaces and Networks Lecture / 21

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

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

(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

Java for Interfaces and Networks

Java for Interfaces and Networks Java for Interfaces and Networks Threads and Networking Federico Pecora School of Science and Technology Örebro University federico.pecora@oru.se Federico Pecora Java for Interfaces and Networks Lecture

More information

CS 251 Intermediate Programming GUIs: Event Listeners

CS 251 Intermediate Programming GUIs: Event Listeners CS 251 Intermediate Programming GUIs: Event Listeners Brooke Chenoweth University of New Mexico Fall 2017 What is an Event Listener? A small class that implements a particular listener interface. Listener

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

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals

More information

Graphical User Interfaces 2

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

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

Java for Interfaces and Networks (DT3029)

Java for Interfaces and Networks (DT3029) Java for Interfaces and Networks (DT3029) Lecture 3 Threads and Networking Federico Pecora federico.pecora@oru.se Center for Applied Autonomous Sensor Systems (AASS) Örebro University, Sweden Capiscum

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Ge?ng user input Overview Displaying message or error Listening for

More information

What is Serialization?

What is Serialization? Serialization 1 Topics What is Serialization? What is preserved when an object is serialized? Transient keyword Process of serialization Process of deserialization Version control Changing the default

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

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 35 April 21, 2014 Swing III: Paint demo, Mouse InteracFon HW 10 has a HARD deadline Announcements You must submit by midnight, April 30 th Demo your

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

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

GUI in Java TalentHome Solutions

GUI in Java TalentHome Solutions GUI in Java TalentHome Solutions AWT Stands for Abstract Window Toolkit API to develop GUI in java Has some predefined components Platform Dependent Heavy weight To use AWT, import java.awt.* Calculator

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

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

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 35 April 15, 2013 Swing III: OO Design, Mouse InteracGon Announcements HW10: Game Project is out, due Tuesday, April 23 rd at midnight If you want

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

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

UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING. A Multithreaded program contains two or more parts that can run concurrently.

UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING. A Multithreaded program contains two or more parts that can run concurrently. UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING 1. What are Threads? A thread is a single path of execution of code in a program. A Multithreaded program contains two or more parts that can run concurrently.

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

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

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

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

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

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN

CSSE 220. Event Based Programming. Check out EventBasedProgramming from SVN CSSE 220 Event Based Programming Check out EventBasedProgramming from SVN Interfaces are contracts Interfaces - Review Any class that implements an interface MUST provide an implementation for all methods

More information

Event Binding. Different Approaches Global Hooks. 2.5 Event Binding 1

Event Binding. Different Approaches Global Hooks. 2.5 Event Binding 1 Event Binding Different Approaches Global Hooks 2.5 Event Binding 1 Event Dispatch vs. Event Binddling Event Dispatch phase addresses: - Which window receives an event? - Which widget processes it? Positional

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

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

AP CS Unit 11: Graphics and Events

AP CS Unit 11: Graphics and Events AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two

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

13 (ono@is.nagoya-u.ac.jp) 2008 1 15 1 factory., factory,. 2 2.,, JFileChooser. 1. Java,,, Serializable *1., FigBase ( 1). FigBase.java 3 5. 1 import java. lang.*; 2 import java. awt.*; 3 import java.

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

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing CSEN401 Computer Programming Lab Topics: Graphical User Interface Window Interfaces using Swing Prof. Dr. Slim Abdennadher 22.3.2015 c S. Abdennadher 1 Swing c S. Abdennadher 2 AWT versus Swing Two basic

More information

2. (True/False) All methods in an interface must be declared public.

2. (True/False) All methods in an interface must be declared public. Object and Classes 1. Create a class Rectangle that represents a rectangular region of the plane. A rectangle should be described using four integers: two represent the coordinates of the upper left corner

More information

Programming Languages 2nd edition Tucker and Noonan"

Programming Languages 2nd edition Tucker and Noonan Programming Languages 2nd edition Tucker and Noonan" Chapter 16 Event-Driven Programming Of all men s miseries the bitterest is this, to know so much and to have control over nothing." " " " " " " "Herodotus

More information

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn Java & Graphical User Interface II Wang Yang wyang AT njnet.edu.cn Outline Review of GUI (first part) What is Event Basic Elements of Event Programming Secret Weapon - Inner Class Full version of Event

More information

Events. Dispatch, event-to-code binding. Review: Events Defined 1/17/2014. occurrence.

Events. Dispatch, event-to-code binding. Review: Events Defined 1/17/2014. occurrence. Events Dispatch, event-to-code binding Review: Events Defined 1. An observable occurrence, phenomenon, or an extraordinary occurrence. 2. A message to notify an application that something happened. Examples:

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

Graphic Interface Programming II Events and Threads. Uppsala universitet

Graphic Interface Programming II Events and Threads. Uppsala universitet Graphic Interface Programming II Events and Threads IT Uppsala universitet Animation Animation adds to user experience Done right, it enhances the User Interface Done wrong, it distracts and irritates

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

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing Rui Moreira Some useful links: http://java.sun.com/docs/books/tutorial/uiswing/toc.html http://www.unix.org.ua/orelly/java-ent/jfc/

More information

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science mluckner@mini.pw.edu.pl http://www.mini.pw.edu.pl/~lucknerm } Abstract Window Toolkit Delegates creation and

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 35 November 30 th 2015 Design PaBerns Model / View / Controller Chapter 31 Game project grading Game Design Proposal Milestone Due: (12 points) Tuesday

More information

Java for Interfaces and Networks (DT3010, HT10)

Java for Interfaces and Networks (DT3010, HT10) Java for Interfaces and Networks (DT3010, HT10) More on Swing and Threads Federico Pecora School of Science and Technology Örebro University federico.pecora@oru.se Federico Pecora Java for Interfaces 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

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

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class CHAPTER GRAPHICAL USER INTERFACES 10 Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/11 10.1 Frame Windows Java provides classes to create graphical applications that can run on any major graphical

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

ECE 462 Object-Oriented Programming using C++ and Java. Key Inputs in Java Games

ECE 462 Object-Oriented Programming using C++ and Java. Key Inputs in Java Games ECE 462 Object-Oriented Programming g using C++ and Java Key Inputs in Java Games Yung-Hsiang Lu yunglu@purdue.edu d YHL Java Key Input 1 Handle Key Events have the focus of the keyboard inputs by calling

More information

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing. COSC User Interfaces Module 3 Sequential vs. Event-driven Programming Example Programs DemoLargestConsole.java DemoLargestGUI.java Demo programs will be available on the course web page. GUI Program Organization

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

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

Java Programming Lecture 9

Java Programming Lecture 9 Java Programming Lecture 9 Alice E. Fischer February 16, 2012 Alice E. Fischer () Java Programming - L9... 1/14 February 16, 2012 1 / 14 Outline 1 Object Files Using an Object File Alice E. Fischer ()

More information

PIC 20A GUI with swing

PIC 20A GUI with swing PIC 20A GUI with swing Ernest Ryu UCLA Mathematics Last edited: November 22, 2017 Hello swing Let s create a JFrame. import javax. swing.*; public class Test { public static void main ( String [] args

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

Component-Based Behavioural Modelling with High-Level Petri Nets

Component-Based Behavioural Modelling with High-Level Petri Nets Component-Based Behavioural Modelling with High-Level Petri Nets Rémi Bastide, Eric Barboni LIIHS IRIT, University of Toulouse, France {bastide, barboni}@irit.fr Software Components Active domain for industry,

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

Class Hierarchy and Interfaces. David Greenstein Monta Vista High School

Class Hierarchy and Interfaces. David Greenstein Monta Vista High School Class Hierarchy and Interfaces David Greenstein Monta Vista High School Inheritance Inheritance represents the IS-A relationship between objects. an object of a subclass IS-A(n) object of the superclass

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

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features: Lecture 28 Exceptions and Inner Classes Goals We are going to talk in more detail about two advanced Java features: Exceptions supply Java s error handling mechanism. Inner classes ease the overhead of

More information

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User CSE3461 Control Flow Paradigms: Reacting to the User Control Flow: Overview Definition of control flow: The sequence of execution of instructions in a program. Control flow is determined at run time by

More information

Events and Exceptions

Events and Exceptions Events and Exceptions Analysis and Design of Embedded Systems and OO* Object-oriented programming Jan Bendtsen Automation and Control Lecture Outline Exceptions Throwing and catching Exceptions creating

More information

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline Sequential vs. Event-driven Programming Reacting to the user GUI Program Organization Let s digress briefly to examine the organization of our GUI programs We ll do this in stages, by examining three example

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

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

Lecture 19 GUI Events

Lecture 19 GUI Events CSE 331 Software Design and Implementation Lecture 19 GUI Events The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous inner classes Proper interaction

More information

Java for Interfaces and Networks (DT3010, HT10)

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

More information

CS11 Java. Fall Lecture 3

CS11 Java. Fall Lecture 3 CS11 Java Fall 2014-2015 Lecture 3 Today s Topics! Class inheritance! Abstract classes! Polymorphism! Introduction to Swing API and event-handling! Nested and inner classes Class Inheritance! A third of

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 36 November 30, 2018 Mushroom of Doom Model / View / Controller Chapter 31 Announcements Game Project Complete Code Due: Monday, December 10th NO LATE

More information

BM214E Object Oriented Programming Lecture 13

BM214E Object Oriented Programming Lecture 13 BM214E Object Oriented Programming Lecture 13 Events To understand how events work in Java, we have to look closely at how we use GUIs. When you interact with a GUI, there are many events taking place

More information

Java GUI Design: the Basics

Java GUI Design: the Basics Java GUI Design: the Basics Daniel Brady July 25, 2014 What is a GUI? A GUI is a graphical user interface, of course. What is a graphical user interface? A graphical user interface is simply a visual way

More information

Bean Communication. COMP434B Software Design. Bean Communication. Bean Communication. Bean Communication. Bean Communication

Bean Communication. COMP434B Software Design. Bean Communication. Bean Communication. Bean Communication. Bean Communication COMP434B Software Design JavaBeans: Events and Reflection Events are the primary mechanism by which Java components interact with each other One Bean generates an event and one or more other Beans receive

More information

GUI Event Handlers (Part I)

GUI Event Handlers (Part I) GUI Event Handlers (Part I) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University 1 Agenda General event

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

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 34 April 13, 2017 Model / View / Controller Chapter 31 How is the Game Project going so far? 1. not started 2. got an idea 3. submitted design proposal

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

CSIS 10A Assignment 14 SOLUTIONS

CSIS 10A Assignment 14 SOLUTIONS 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,

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Spring 2017 GUI Event-Driven Programming 1 The plan User events and callbacks Event objects Event listeners Registering listeners to handle events Anonymous

More information

Job Migration. Job Migration

Job Migration. Job Migration Job Migration The Job Migration subsystem must provide a mechanism for executable programs and data to be serialized and sent through the network to a remote node. At the remote node, the executable programs

More information

CS506 Web Design & Development Final Term Solved MCQs with Reference

CS506 Web Design & Development Final Term Solved MCQs with Reference with Reference I am student in MCS (Virtual University of Pakistan). All the MCQs are solved by me. I followed the Moaaz pattern in Writing and Layout this document. Because many students are familiar

More information

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

CSE 331 Software Design and Implementation. Lecture 19 GUI Events CSE 331 Software Design and Implementation Lecture 19 GUI Events Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 7 due Thursday 8/9 Homework 8 due Thursday 8/9 HW8 has a regression testing

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

Java: Graphical User Interfaces (GUI)

Java: Graphical User Interfaces (GUI) Chair of Software Engineering Carlo A. Furia, Marco Piccioni, and Bertrand Meyer Java: Graphical User Interfaces (GUI) With material from Christoph Angerer The essence of the Java Graphics API Application

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

Window Interfaces Using Swing Objects

Window Interfaces Using Swing Objects Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs

More information

Object-Oriented Software Engineering. PersonGui (Mark 1) Case Study

Object-Oriented Software Engineering. PersonGui (Mark 1) Case Study Object-Oriented Software Engineering PersonGui (Mark 1) Case Study Contents The PersonGui (Mark1) The The Person Gui (Mark1) ToolBar PersonGui Constructor Adding Buttons Making Buttons Handling Events

More information

Packages: Putting Classes Together

Packages: Putting Classes Together Packages: Putting Classes Together 1 Introduction 2 The main feature of OOP is its ability to support the reuse of code: Extending the classes (via inheritance) Extending interfaces The features in basic

More information

Java for Interfaces and Networks (DT3029)

Java for Interfaces and Networks (DT3029) Java for Interfaces and Networks (DT3029) Lecture 9 More on Swing and Threads Federico Pecora federico.pecora@oru.se Center for Applied Autonomous Sensor Systems (AASS) Örebro University, Sweden www.clipartlord.com

More information

CIS 120 Programming Languages and Techniques. Final Exam, May 3, 2011

CIS 120 Programming Languages and Techniques. Final Exam, May 3, 2011 CIS 120 Programming Languages and Techniques Final Exam, May 3, 2011 Name: Pennkey: My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in

More information

Handling Mouse and Keyboard Events

Handling Mouse and Keyboard Events Handling Mouse and Keyboard Events 605.481 1 Java Event Delegation Model EventListener handleevent(eventobject handleevent(eventobject e); e); EventListenerObject source.addlistener(this);

More information

Introduction to concurrency and GUIs

Introduction to concurrency and GUIs Principles of Software Construction: Objects, Design, and Concurrency Part 2: Designing (Sub)systems Introduction to concurrency and GUIs Charlie Garrod Bogdan Vasilescu School of Computer Science 1 Administrivia

More information

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1 Java Swing based on slides by: Walter Milner Java Swing Walter Milner 2005: Slide 1 What is Swing? A group of 14 packages to do with the UI 451 classes as at 1.4 (!) Part of JFC Java Foundation Classes

More information

Anonymous Classes. A short-cut for defining classes when you want to create only one object of the class.

Anonymous Classes. A short-cut for defining classes when you want to create only one object of the class. Anonymous Classes A short-cut for defining classes when you want to create only one object of the class. Why Anonymous Class? Sometime we must define a class just to create only one instance of the class.

More information

Programming Mobile Devices J2SE GUI

Programming Mobile Devices J2SE GUI Programming Mobile Devices J2SE GUI University of Innsbruck WS 2009/2010 thomas.strang@sti2.at Graphical User Interface (GUI) Why is there more than one Java GUI toolkit? AWT write once, test everywhere

More information

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1 Datenbank-Praktikum Universität zu Lübeck Sommersemester 2006 Lecture: Swing Ho Ngoc Duc 1 Learning objectives GUI applications Font, Color, Image Running Applets as applications Swing Components q q Text

More information

MIT AITI Swing Event Model Lecture 17

MIT AITI Swing Event Model Lecture 17 MIT AITI 2004 Swing Event Model Lecture 17 The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the user. But how do GUIs interact with users? How do applications

More information