Listener - A Graphical User Interfaces (GUI) is created...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
A Graphical User Interfaces (GUI) is created with at least three kinds of objects in order to receive user input and process it. - components (e.g., buttons, textfields) -listeners – waits for events to occur -events (e.g., a button is pushed, a mouse is moved) An Event is an object that represents some activity to which we may want to respond. To create a GUI program: -- Define and set up the components -- Create a listener object by writing a class that implements a particular listener interface. (The Java standard class library contains several interfaces that corresponds to particular event categories.) -- After creating the listener, we add the listener to the component that might generate the event to set up a formal relationship between the generator and listener. -- Define what happens in response to each event of interest. Event Generator Listener This object may generate an event It waits for and responds to an event When an event occurs, the generator calls the appropriate method of the listener, passing an object that describes the event.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
A GUI Example using JButton and ActionListener: // from Lewis/Loftus textbook import java.awt.*; import java.awt.event.*; //to use ActionListener and ActionEvent import javax.swing.*; public class PushCounter extends JApplet { private int pushes; //declared as instance variables so that it can be used private JLabel label; // in more than one method.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/25/2010 for the course CSE 71682 taught by Professor Nakamura during the Spring '10 term at ASU.

Page1 / 5

Listener - A Graphical User Interfaces (GUI) is created...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online