// File: ex7.java (Module 9) // // Template for ex 9.7. 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); this.setLayout (new FlowLayout()); // Quit button Button b = new Button ("Quit"); b.setBackground (Color.red); b.setFont (new Font ("Serif", Font.PLAIN | Font.BOLD, 15)); b.addActionListener (this); this.add (b); // Show the frame. this.setVisible (true); } // This method is required to implement the // ActionListener interface. public void actionPerformed (ActionEvent a) { String event_desc = a.getActionCommand(); if (event_desc.equalsIgnoreCase("Quit")) System.exit (0); // Force a call to the paint() method. this.repaint(); } } // End of class "NewFrame" public class ex7 { public static void main (String[] argv) { NewFrame nf = new NewFrame (300, 200); } }