An Example of an Applet with a Button
Here's an applet that puts up a single Button labeled "Beep." The
Button is added to the applet. Then a BeepAction object is set to handle
the Button's ActionEvents with the addActionListener() method.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class BeepApplet extends Applet {
  
   public void init () {
   
     // Construct the button
     Button beep = new Button("Beep");
     // add the button to the layout
     this.add(beep);
     // specify that action events sent by this
     // button should be handled by a new BeepAction object
     beep.addActionListener(new BeepAction());
   
   }
}
Previous | Next | Top
Last Modified November 5, 1997
Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu