The Java Program: Quit2.java

  1 // Quit.java -- Swing application with just a quit button
  2 
  3 import java.awt.*;
  4 import java.awt.event.*;
  5 import javax.swing.*;
  6 
  7 public final class Quit2 extends JFrame implements ActionListener {
  8 
  9    private Quit2 () {
 10       super ("Quit");
 11       final JButton button = new JButton ("Quit");
 12       button.addActionListener (this);
 13       getContentPane().add(button);
 14       setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // Requires Java 1.3
 15    }
 16 
 17    public void actionPerformed (ActionEvent e) {
 18       this.setVisible (false);
 19       this.dispose();
 20    }
 21 
 22    public static void createAndShowGUI () {
 23       JFrame.setDefaultLookAndFeelDecorated(true);
 24       final JFrame frame = new Quit2 ();
 25       frame.pack();
 26       frame.setVisible(true);
 27    }
 28 
 29    public static void main (String[] args) {
 30       SwingUtilities.invokeLater (new Runnable () {
 31           public void run() { createAndShowGUI();}
 32       });
 33    }
 34 }