listenerHw6Fall10 - A Graphical User Interfaces(GUI is created with at least three kinds of objects in order to receive user input and process

listenerHw6Fall10 - A Graphical User Interfaces(GUI is...

This preview shows page 1 - 3 out of 5 pages.

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.
A GUI Example using JButton and ActionListener: // PushCounter.java--modified 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.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture