|
|
Listing of Listener1.java
// Swing implementation
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Listener1
extends Applet implements ActionListener
{
public Listener1()
{
super();
Button myButton = new Button ("Click me!");
add(myButton);
myButton.addActionListener(this);
}
public void actionPerformed
(ActionEvent e)
{
// Do something here when the user clicks the button
// display a window saying "ouch"
// (JoptionPane is a 'Swing' component)
JOptionPane.showMessageDialog(null, "ouch!");
}
} // class
|
|