//Program to demonstrate action listeners and event handlers 
import java.awt.*; 
import java.awt.event.*; 
class Gui extends Frame implements ActionListener, WindowListener
{ public Gui(String s) //constructor 
  { super(s);
    setBackground(Color.yellow); 
    setLayout(new FlowLayout());
    addWindowListener(this);      //listen for events on this Window 
    Button pushButton = new Button("press me");
    add(pushButton);
    pushButton.addActionListener(this); //listen for Button press 
  } 
  //define action for Button press
  public void actionPerformed(ActionEvent event)
  { final char bell = '\u0007'; 
    if (event.getActionCommand().equals("press me"))
    { System.out.print(bell); }
  } 
  //define methods in WindowListener interface
    public void windowClosing(WindowEvent event) { System.exit(0); } 
    public void windowClosed(WindowEvent event) {} //do nothing
    public void windowDeiconified(WindowEvent event){} 
    public void windowIconified(WindowEvent event){} 
    public void windowActivated(WindowEvent event){} 
    public void windowDeactivated(WindowEvent event){} 
    public void windowOpened(WindowEvent event){} 
 } 
