// File: TestAwt22.java (Module 9) // // Author: Rahul Simha // Created: October 21, 1998 // // Quit button - handling the event. import java.awt.*; import java.awt.event.*; // Needed for ActionListener. class NewFrame extends Frame implements ActionListener { // Constructor. public NewFrame (int width, int height) { // Set the title and other frame parameters. this.setTitle ("Button example"); this.setResizable (true); this.setBackground (Color.cyan); this.setSize (width, height); // Create a new button. Button b = new Button ("Quit"); // Set the background color of the button. b.setBackground (Color.red); // Set the font of the button label. b.setFont (new Font ("Serif", Font.PLAIN | Font.BOLD, 15)); // Add an ActionListener to the button. b.addActionListener (this); // BorderLayout is already the manager so // we leave the setLayout commented out. // this.setLayout (new BorderLayout()); // Add the button to the south of the frame. this.add (b, BorderLayout.SOUTH); // Show the frame. this.setVisible (true); } // This method is required to implement the // ActionListener interface. public void actionPerformed (ActionEvent a) { // Button must have been pressed - so really quit. System.exit (0); } } // End of class "NewFrame" public class TestAwt22 { public static void main (String[] argv) { NewFrame nf = new NewFrame (300, 200); } }