Bean Communication. COMP434B Software Design. Bean Communication. Bean Communication. Bean Communication. Bean Communication
|
|
- Wilfrid Crawford
- 5 years ago
- Views:
Transcription
1 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 it Java 1.0 event model was based on the component containment hierarchy If a component didn t handle a particular event then it propagated up to the containing component Simple - OK for writing basic applets Doesn t scale well to complicated interfaces 2 Java 1.1 delegation event model Provides a standard mechanism for a source to generate an event and send it to a set of listeners Event An object that describes some state change in a source Can be generated when a user interacts with an element in a GUI Eg pressing a button, moving a slider, dragging the mouse etc Events may also be generated that are not directly caused by user input Eg arrival of incoming data, expiration of a software timer, overflow of a buffer 3 Java 1.1 delegation event model A source - generate events Sources have three main responsibilities: Provide methods that allow listeners to register and deregister for notifications about a specific type of event Generate events Send events to all registered listeners Multiple listeners - multicasting Single listener - unicasting 4 Java 1.1 delegation event model Registering and deregistering methods: public void addtypelistener(typelistener el) public void addtypelistener(typelistener el) throws TooManyListenersException Public void removetypelistener(typelistener el) Type is the type of the event, and el is the event listener Eg. javax.swing.abstractbutton Provides common behaviours for buttons and menu items (subclasses: JButton, JMenuItem, JToggleButton) Generates an action event when pressed/selected public void addactionlistener(actionlistener al) public void removeactionlistener(actionlistener al) 5 Java 1.1 delegation event model A listener - receives event notifications Listeners have three main responsibilities Register to receive notifications about specific events Call appropriate registration method of the source Implement an interface to receive events of that type Deregister if it no longer wants to receive notifications about a specific type of event Call appropriate deregistration method of the source 6 1
2 Eg. ActionListener interface provides one method to receive action events void actionperformed(actionevent ae) ae is the ActionEvent object generated by the source When a button is pressed, the actionperformed method of all registered listeners is invoked and the event is passed as an argument to that method Event classes A set of classes is provided to represent the various types of UI events (AWT events) Object EventObject AWTEvent ActionEvent AdjustmentEvent ComponentEvent ItemEvent TextEvent ContainerEvent FocusEvent InputEvent PaintEvent WindowEvent 7 KeyEvent 8MouseEvent Event classes EventObject class extends Object Is part of the java.util package Is the superclass of all event state objects Constructor : EventObject(Object source) Source is the object that generates the event Has two methods : Object getsource() - return the generating object String tostring() - return a String equivalent of the event Event classes AWTEvent class extends EventObject Is part of the java.awt package All AWT event types are subclasses of AWTEvent One of its constructors: AWTEvent(Object source, int id) Source is the object generating the event, id identifies the type of event Two frequently used methods: int getid() String tostring() 9 10 AWT Events Examples Listener interfaces EventListener interface is part of the java.util package It does not define any constants or methods, but exists only to identify those interfaces that process events All event listener interfaces must extend this interface Events typically have a corresponding listener interface BlahEvent - BlahListener 11 Action and Item Events Usually generated when buttons are pressed and menu items are selected respectively package actionevents; import javax.swing.jbutton; public class ActionSource1 extends JButton { public ActionSource1() { super("actionsource1"); 2
3 package actionevents; import javax.swing.jcombobox; public class ActionSource2 extends JComboBox { public ActionSource2() { additem("item 1"); additem("item 2"); additem("item 3"); package actionevents; import javax.swing.jtextarea; public class ActionReceiver extends JPanel implements ActionListener, ItemListener { private JTextArea ta; public ActionReceiver() { ta = new JTextArea(10,20); add(ta); public void actionperformed(actionevent ae) { String ac = ae.getactioncommand(); int modifiers = ae.getmodifiers(); String s = ac; if((modifiers & ActionEvent.ALT_MASK)!= 0) { s += ", ALT_MASK"; if((modifiers & ActionEvent.CTRL_MASK)!= 0) { s += ", CTRL_MASK"; if((modifiers & ActionEvent.META_MASK)!= 0) { s += ", META_MASK"; if((modifiers & ActionEvent.SHIFT_MASK)!= 0) { s += ", SHIFT_MASK"; ta.append(s + "\n"); public void itemstatechanged(itemevent e) { String item = (String)e.getItem(); String info = (e.getstatechange() == ItemEvent.SELECTED)? " (selected)" : " (deselected)"; ta.append(item+info+"\n"); public class ActionEventsDemo { public static void main(string [] args) { ActionSource1 as1 = new ActionSource1(); ActionSource2 as2 = new ActionSource2(); ActionReceiver ar = new ActionReceiver(); if (mode == 1) { as1.setbounds(10,10,150,30); jf.getcontentpane().add(as1); as1.addactionlistener(ar); else { as2.setbounds(10,10,150,30); jf.getcontentpane().add(as2); as2.addactionlistener(ar); as2.additemlistener(ar); AWT Events Examples Mouse Events Are generated when the mouse is clicked, dragged, moved, pressed or released (also when mouse pointer enters or exits a component) MouseEvent class defines many int constants MOUSE_CLICKED, MOUSE_DRAGGED, MOUSE_ENTERED, MOUSE_EXITED etc Some commonly used methods of MouseEvent: Point getpoint() - returns a Point object encapsulating the position of the mouse getx(), gety() - return the x and y coordinates of the mouse Two listener interfaces - MouseListener and MouseMotionListener 18 3
4 package mouseevents; public class MouseSource extends JPanel { public MouseSource() { Dimension d = new Dimension(100,100); setminimumsize(d); setpreferredsize(d); setmaximumsize(d); public void paintcomponent(graphics g) { super.paintcomponent(g); Dimension d = getsize(); g.drawrect(0, 0, d.width 1, d.height 1); package mouseevents; import javax.swing.jtextarea; import javax.swing.jscrollpane; public class MouseReceiver extends JPanel implements MouseListener, MouseMotionListener { private JTextArea ta; public MouseReceiver() { ta = new JTextArea(15, 40); JScrollPane js = new JScrollPane(ta); add(js); public void mouseclicked(mouseevent me) { ta.append("mouse clicked\n"); public void mouseentered(mouseevent me) { ta.append("mouse entered\n"); public void mouseexited(mouseevent me) { ta.append("mouse exited\n"); public void mousepressed(mouseevent me) { ta.append("mouse pressed\n"); public void mousereleased(mouseevent me) { ta.append("mouse released\n"); public void mousedragged(mouseevent me) { ta.append("mouse dragged\n"); Adapter Classes An adapter class provides empty implementations of all methods defined in a specific event listener interface Useful if you only want to process a subset of the events that are received by a particular interface MouseListener has five methods. If for example you only wanted to process mouseclicked() then your class could extend MouseAdapter and overide only the mouseclicked method Can t be used in this way if your class already extends some other class public void mousemoved(mouseevent me) { ta.append("mouse moved\n"); 22 Anonymous Inner Classes An inner class is one that is defined within the scope of another class Has access to all the variables and methods of the enclosing class An anonymous inner class is one that does not have a name Use when you only ever need one object of the class Can be extremely useful when writing code to process events 23 package dot; public class Dot extends JPanel { private Point p; public Dot() { Dimension d = new Dimension(200, 200); setminimumsize(d); setpreferredsize(d); setmaximumsize(d); p = new Point(100, 100); addmouselistener(new MouseAdapter() { public void mouseclicked(mouseevent me) { changepoint(me.getpoint()); ); 4
5 public void changepoint(point newp) { p = newp; repaint(); public void paintcomponent(graphics g) { super.paintcomponent(g); Dimension d = getsize(); g.drawrect(0, 0, d.width 1, d.height 1); g.fillrect(p.x 2, p.y 2, 4, 4); Dynamic Event Handlers java.beans.eventhandler (introduced in Java 1.3) Provides support for dynamically generating event listeners Can handle simple situation where event listener methods execute a single statement involving an incoming event and a target object Only provides a subset of what can be done with inner classes However, memory and disk footprint is smaller than for inner classes Using EventHandler requires one class per listener type, using anonymous inner classes requires one class per 26 listener object java.beans.eventhandler Has various static factory methods for creating proxy objects that implement a given listener interface EventHandler objects are used behind the scenes to encapsulate info about the event, the target object, the method to call on the target and any argument to the method java.lang.reflect.proxy class implements listener methods; calls to listener methods are encoded and passed on to the EventHandler s invoke method 27 package dotv2; import java.beans.eventhandler; public class Dot extends JPanel { private Point p; public Dot() { Dimension d = new Dimension(200, 200); Object handler = EventHandler.create(MouseListener.class, this, "changepoint", "point", "mouseclicked"); addmouselistener((mouselistener)handler); java.beans.eventhandler Intended to be used by builder tools we will see how later Removes the need for Beans to implement specific listener interfaces Allows builder tools to connect arbitrary beans together Weaker typing specific listener interfaces implemented by a bean can be bypassed Limited to transferring a single property from source event or bean to target bean 29 package actioneventsv2; public class ActionSource2 extends JComboBox { public String getcurrentselecteditemtext() { return getselecteditem().tostring(); public ActionSource2() { additem("item 1"); additem("item 2"); additem("item 3"); public class ActionReceiver extends JPanel { private JTextArea ta; public ActionReceiver() { ta = new JTextArea(10,20); add(ta); public void accepttext(string text) { ta.append(text + "\n"); 5
6 package mouseeventsv2; public class MouseReceiver extends JPanel { private JTextArea ta; public MouseReceiver() { ta = new JTextArea(15, 40); JScrollPane js = new JScrollPane(ta); add(js); public void mouseclicked() { ta.append("mouse clicked\n"); public void mouseentered() { ta.append("mouse entered\n"); Custom Events Custom events are useful when one of your objects wants to notify another object about a change in its state Six steps involved: You must define a new class to describe the event (must extend EventObject) You must define a new interface for listeners to receive this type of event (must extend EventListener) The source must provide methods to allow listeners to register and deregister for event notifications The source must provide code to generate the event and send it to all registered listeners The listener must implement the interface to receive the event The listener must register/deregister to receive the notifications public void mouseexited() { ta.append("mouse exited\n"); 32 Colour Event Example package cselector; import java.util.*; public class ColorEvent extends EventObject { private Color color; public ColorEvent(Object source, Color color) { super(source); this.color = color; public Color getcolor() { return color; package cselector; import java.util.*; public interface ColorListener extends EventListener { public void changecolor(colorevent ce); package cselector; public class Painter extends JPanel implements ColorListener { private Color color; // constructor + paintcomponent method omitted see source public void setcolor(color c) { color = c; repaint(); public void changecolor(colorevent ce) { color = ce.getcolor(); repaint(); package cselector; import java.beans.*; import java.util.*; import javax.swing.jscrollbar; import javax.swing.jlabel; public class Selector extends JPanel implements AdjustmentListener { private Color color; private Vector listeners; private JScrollBar rscrollbar, gscrollbar, bscrollbar; // constructor, paintcomponent & scrollbar handling code // omitted see source for details public Color getcolor() { return color; public void firecolorevent(colorevent ce) { Vector v; synchronized(this) { v = (Vector)listeners.clone(); for(int i = 0; i < v.size(); i++) { ColorListener cl = (ColorListener)v.elementAt(i); cl.changecolor(ce); public void addcolorlistener(colorlistener cl) { listeners.addelement(cl); public void removecolorlistener(colorlistener cl) { listeners.removeelement(cl); 6
7 Reflection and Introspection Reflection is the ability to obtain information about the fields, constructors and methods of a class at runtime The typical Bean developer does not write code that uses reflection directly However, it is useful to have some understanding of reflection because Introspection is based on it Class Reflection The Java Virtual Machine creates an instance of the class java.lang.class for each type, including classes, interfaces, arrays, and simple types Class provides various instance methods that allow you to get information about that type Provides more than 30 different instance methods! See the javadocs package reflect; public class IsInterfaceDemo { public static void main(string args[]) { try { Reflection // Get the class object Class c = Class.forName(args[0]); The java.lang.reflect package contains interfaces and classes that encapsulate information about constructors, methods, fields etc. Eg. java.lang.reflect.field contains methods that allow you to read and write the value of a field within another object (subject to Java language access control) // Determine if it represents a class or interface if(c.isinterface()) { System.out.println(args[0] + " is an interface"); else { System.out.println(args[0] + " is not an interface"); catch(exception ex) { // the printstacktrace method is extremely useful for // debugging :-) ex.printstacktrace(); 40 package reflect; import java.lang.reflect.*; public class GetFieldsDemo { public static void main(string args[]) { try { // Get the class object Class c = Class.forName(args[0]); // Display the fields Field fields[] = c.getfields(); for(int i = 0; i < fields.length; i++) { System.out.println(fields[i].getName()); catch(exception ex) { ex.printstacktrace(); Reflection The class Method in java.lang.reflect alows you to get information about a method Some methods in Method: Class [] getexceptiontypes() Class [] getparametertypes() Class getreturntype() Object invoke(object obj, Object [] args) Allows a builder tool to dynamically invoke a method of a Bean! This is exactly what is needed to customize a Bean by accessing its properties and to connect several Beans 42 7
8 package reflect; import java.lang.reflect.*; // invoke a method in a class, where the class name, // method name, and any args are supplied on the // command line public class InvokeDemo { public static void main(string args[]) { try { // Get the class object Class c = Class.forName(args[0]); // Get reference to Method object int nparameters = args.length 2; Class parametertypes[] = new Class[nparameters]; for(int i = 0; i < nparameters; i++) { parametertypes[i] = double.class; Method m = c.getmethod(args[1], parametertypes); // Generate parameters array Object parameters[] = new Double[nparameters]; for(int i = 0; i < nparameters; i++) { parameters[i] = new Double(args[i + 2]); // Invoke method Object r; if(modifier.isstatic(m.getmodifiers())) { r = m.invoke(null, parameters); else { r = m.invoke(c.newinstance(), parameters); // Display results if (r!= null) { System.out.println(r); catch(exception ex) { ex.printstacktrace(); 8
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 informationGUI 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 informationModule 4 Multi threaded Programming, Event Handling. OOC 4 th Sem, B Div Prof. Mouna M. Naravani
Module 4 Multi threaded Programming, Event Handling OOC 4 th Sem, B Div 2017-18 Prof. Mouna M. Naravani Event Handling Complete Reference 7 th ed. Chapter No. 22 Event Handling Any program that uses a
More informationThe 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 informationUNIT-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 informationMethod 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 informationGUI 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 informationCOMPSCI 230. Software Design and Construction. Swing
COMPSCI 230 Software Design and Construction Swing 1 2013-04-17 Recap: SWING DESIGN PRINCIPLES 1. GUI is built as containment hierarchy of widgets (i.e. the parent-child nesting relation between them)
More informationEvent 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 informationGraphical 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 informationG51PGP 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 informationOutline. 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 information11/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(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 informationJava 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 informationInheritance. 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 informationProperty Editors and Customizers. COMP434 Software Design. Property Editors. Property Editors and. Property Editors.
COMP434 Software Design and Customizers and Customizers A property editor allows the user to read and modify the value of one property A customizer provides a graphical user interface that allows the user
More informationG51PRG: 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 informationCSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 143 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/
More informationClass 16: The Swing Event Model
Introduction to Computation and Problem Solving Class 16: The Swing Event Model Prof. Steven R. Lerman and Dr. V. Judson Harward 1 The Java Event Model Up until now, we have focused on GUI's to present
More informationPreviously, 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 informationControl 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 informationProgramming 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 informationModule 4 Multi threaded Programming, Event Handling. OOC 4 th Sem, B Div Prof. Mouna M. Naravani
Module 4 Multi threaded Programming, Event Handling OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani Event Handling Any program that uses a graphical user interface, such as a Java application written
More informationGraphical 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 informationGraphical 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 informationComputer 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 informationExample 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 informationGUI 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 informationCSE 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 informationLecture 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 informationJava Event Handling -- 1
Java Event Handling -- 1 Event Handling Happens every time a user interacts with a user interface. For example, when a user pushes a button, or types a character. 2 A Typical Situation: Scrollbar AWTEvent
More information10/16/2008. CSG 170 Round 5. Prof. Timothy Bickmore. User Analysis Task Analysis (6) Problem Scenarios (3)
Human-Computer Interaction CSG 170 Round 5 Prof. Timothy Bickmore T2: Requirements Analysis Review User Analysis Task Analysis (6) Problem Scenarios (3) 1 T2 Review Requirements Analysis Who is the user?
More informationCS 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 informationUser 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 informationGUI 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 informationAssignment No 2. Year: Dept.: ComputerTech. Sanjivani Rural Education Society s Sanjivani KBP Polytechnic, Kopargaon
Year: 015-16 ACAD/F/3 Subject: AJP(1765) Division:CMTA(CM6G) Pages: 1-7 CHAPTER :Event Handling(0 Marks) Q.1 package contains all the classes and methods required for Event handling in java. (a) java.applet
More informationDr. Hikmat A. M. AbdelJaber
Dr. Hikmat A. M. AbdelJaber GUI are event driven (i.e. when user interacts with a GUI component, the interaction (event) derives the program to perform a task). Event: click button, type in text field,
More informationCSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 331 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/
More informationGUI Software Architecture
GUI Software Architecture P2: Requirements Analysis User Analysis Task Analysis Problem Scenarios Usability Criteria Scenario Your engineers just developed a new desktop computer. They give you the following
More informationCSE 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 informationGUI (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 informationGUI 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 informationJava 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 informationBM214E 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 informationUnit 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 informationCSSE 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 informationJava & 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 informationMarcin 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 informationGUI 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 informationAdvanced 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 informationCourse Structure. COMP434/534B Software Design Component-based software architectures. Components. First term. Components.
COMP434/534B Software Design Component-based software architectures Course Structure Two six week modules First term (me) Introduction to Sun s JavaBeans framework One two hour lecture per week for the
More informationPIC 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 informationCourse Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski
CS 190 - Java Introduction to Java Andy Mroczkowski uamroczk@cs.drexel.edu Department of Computer Science Drexel University March 10, 2008 / Lecture 8 Outline Course Status Course Information & Schedule
More informationWhich 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 informationCourse: CMPT 101/104 E.100 Thursday, November 23, 2000
Course: CMPT 101/104 E.100 Thursday, November 23, 2000 Lecture Overview: Week 12 Announcements Assignment 6 Expectations Understand Events and the Java Event Model Event Handlers Get mouse and text input
More informationGUI Event Handlers (Part II)
GUI Event Handlers (Part II) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University 1 Agenda Listener
More informationGraphics. Lecture 18 COP 3252 Summer June 6, 2017
Graphics Lecture 18 COP 3252 Summer 2017 June 6, 2017 Graphics classes In the original version of Java, graphics components were in the AWT library (Abstract Windows Toolkit) Was okay for developing simple
More informationPackages: 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 informationPESIT 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 informationInteracción con GUIs
Interacción con GUIs Delegation Event Model Fuente EVENTO Oyente suscripción Fuente Oyente suscripción EVENTO Adaptador EVENTO java.lang.object java.util.eventobject java.awt.awtevent java.awt.event. ActionEvent
More informationProgramming 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 informationMIT 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 informationjavax.swing Swing Timer
27 javax.swing Swing SwingUtilities SwingConstants Timer TooltipManager JToolTip 649 650 Swing CellRendererPane Renderer GrayFilter EventListenerList KeyStroke MouseInputAdapter Swing- PropertyChangeSupport
More informationCS211 GUI Dynamics. Announcements. Motivation/Overview. Example Revisted
CS211 GUI Dynamics Announcements Prelim 2 rooms: A-M are in Olin 155 N-A are in Olin 255 Final exam: final exam 5/17, 9-11:30am final review session (TBA, likely Sun 5/15) Consulting: regular consulting
More informationPROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7
PROGRAMMING DESIGN USING JAVA (ITT 303) Graphical User Interface Unit 7 Learning Objectives At the end of this unit students should be able to: Build graphical user interfaces Create and manipulate buttons,
More informationCheng, CSE870. More Frameworks. Overview. Recap on OOP. Acknowledgements:
More Frameworks Acknowledgements: K. Stirewalt. Johnson, B. Foote Johnson, Fayad, Schmidt Overview eview of object-oriented programming (OOP) principles. Intro to OO frameworks: o Key characteristics.
More informationProgramming 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 informationCSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 331 Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT Lecturer: Michael Hotan slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer,
More informationLecture 9 : Basics of Reflection in Java
Lecture 9 : Basics of Reflection in Java LSINF 2335 Programming Paradigms Prof. Kim Mens UCL / EPL / INGI (Slides partly based on the book Java Reflection in Action, on The Java Tutorials, and on slides
More informationCS2110. 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 informationHandling 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 informationCS2110. 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 informationCS2110. 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 informationProgramming 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 informationHW#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 informationCSEN401 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 informationChapter 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 informationHandout 14 Graphical User Interface (GUI) with Swing, Event Handling
Handout 12 CS603 Object-Oriented Programming Fall 15 Page 1 of 12 Handout 14 Graphical User Interface (GUI) with Swing, Event Handling The Swing library (javax.swing.*) Contains classes that implement
More informationCOSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 123 Computer Creativity Graphics and Events Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) Draw shapes, text in various fonts, and colors. 2) Build
More informationGUI Programming: Swing and Event Handling
GUI Programming: Swing and Event Handling Sara Sprenkle 1 Announcements No class next Tuesday My Fourth of July present to you: No quiz! Assignment 3 due today Review Collections: List, Set, Map Inner
More informationCS2110. 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 informationChapter 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 informationI/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 informationChapter 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 information8/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 informationH212 Introduction to Software Systems Honors
Introduction to Software Systems Honors Lecture #15: October 21, 2015 1/34 Generic classes and types Generic programming is the creation of programming constructs that can be usedwith many different types.
More informationTopic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"
More informationTopic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques
More informationComponent-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 informationProgramming 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 informationAP 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 informationJava 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 informationVirtualians.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 informationOverloading Example. Overloading. When to Overload. Overloading Example (cont'd) (class Point continued.)
Overloading Each method has a signature: its name together with the number and types of its parameters Methods Signatures String tostring() () void move(int dx,int dy) (int,int) void paint(graphicsg) (Graphics)
More information14.2 Java s New Nimbus Look-and-Feel 551 Sample GUI: The SwingSet3 Demo Application As an example of a GUI, consider Fig. 14.1, which shows the SwingS
550 Chapter 14 GUI Components: Part 1 14.1 Introduction 14.2 Java s New Nimbus Look-and-Feel 14.3 Simple GUI-Based Input/Output with JOptionPane 14.4 Overview of Swing Components 14.5 Displaying Text and
More informationCSE1720. Objectives for this class meeting 2/10/2014. Cover 2D Graphics topic: displaying images. Timer class, a basic ActionListener
CSE1720 Click to edit Master Week text 05, styles Lecture 09 Second level Third level Fourth level Fifth level Winter 2014! Tuesday, Feb 4, 2014 1 Objectives for this class meeting Cover 2D Graphics topic:
More informationTable of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...
Table of Contents Chapter 1 Getting Started with Java SE 7 1 Introduction of Java SE 7... 2 Exploring the Features of Java... 3 Exploring Features of Java SE 7... 4 Introducing Java Environment... 5 Explaining
More informationWhat 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 informationProgramming Language Concepts: Lecture 9
Programming Language Concepts: Lecture 9 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in PLC 2011, Lecture 9, 10 February 2011 The event queue OS passes on low-level events to run-time
More information