Alternate Patterns for Events

Since ActionListener is an interface and not a class, it can be implemented wherever is convenient. For example, an applet can handle its own events like this:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class BeepApplet extends Applet implements ActionListener {
   public void init () {
     // Construct the button
     Button beep = new Button("Beep");

     // add the button to the layout

     // specify that action events sent by this
     // button should be handled by the applet itself

  public void actionPerformed(ActionEvent e) {



The main benefit of this event model is that the GUI can be separated from the code.
Previous | Next | Top | Cafe au Lait

Copyright 1997 Elliotte Rusty Harold
Last Modified November 5, 1997