// chap_10\Ex_3.java // program to demonstrate action listeners and event handlers import java.awt.*; import java.awt.event.*; class Gui extends Frame implements ActionListener, WindowListener { // constructor public Gui(String s) { super(s); setBackground(Color.yellow); setLayout(new FlowLayout()); addWindowListener(this); Button pushButton = new Button("press me"); add(pushButton); pushButton.addActionListener(this); } public void windowClosed(WindowEvent event){} 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){} public void windowClosing(WindowEvent event) { System.exit(0); } public void actionPerformed(ActionEvent event) { final char bell = '\u0007'; if (event.getActionCommand().equals("press me")) { System.out.print(bell); } } } class Ex_3 { public static void main(String[] args) { Gui screen = new Gui("Example 3"); screen.setSize(500,100); screen.setVisible(true); } }