import java.awt.*;
import java.awt.event.*;
public class buttonDemo extends Frame implements ActionListener
{
Button bChange = new Button("Click Me!"); // construct a Button
buttonDemo() // constructor for buttonDemo
{
setLayout( new FlowLayout() ); // choose the layout manager
bChange.addActionListener( this ); // register the buttonDemo object
// as the listener for its Button.
add( bChange ); // add the button to the container
}
public void actionPerformed( ActionEvent evt)
{
setBackground( Color.blue );
repaint(); // ask the system to paint the screen.
}
public static void main ( String[] args )
{
buttonDemo frm = new buttonDemo();
WindowQuitter wquit = new WindowQuitter();
frm.addWindowListener( wquit );
frm.setSize( 200, 150 );
frm.setVisible( true );
}
}
class WindowQuitter extends WindowAdapter
{
public void windowClosing( WindowEvent e )
{
System.exit( 0 ); // what to do for this event--exit the program
}
}
|