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.

You will only see something here if your browser supports Java 1.1.

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 | Cafe au Lait

Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified November 5, 1997