Basic HTML version of Foils prepared Sept 21 1998

Foil 34 Setting up ActionEvents for a Button

From Java Tutorial 98- 3: Graphics and the Abstract Windowing Toolkit NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken


1 When the button is created, it should have at least one listener class added to its list of listeners:
  • button1.addActionListener ( eventclass );
2 where eventclass is an instance of the listener class.
  • every component which can cause an event called X, has methods addXListener and removeXListener.
3 Then this class must implement the interface ActionListener. This interface requires only one event handler method:
  • public class EventClass implements ActionListener
  • {
  • public void actionPerformed ( ActionEvent e) { ... }
  • }
4 If the event source class is acting as its own listener, then you just say
  • button1.addActionListener ( this );

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998