package utilities;

import java.awt.Color;
import javax.swing.*;
import java.awt.event.*;

    /** A Quit button that will always quit an application when pressed.
     */
public class QuitJButton extends JButton implements ActionListener {
        /** Create a Quit button with the given string and icon.
         */
    public QuitJButton(String s,Icon i){
        super(s,i);
        addActionListener(this);
    }

        /** Create a Quit button with the given string.
         */
    public QuitJButton(String s){
        this(s,null);
    }

        /** Create a Quit button with the given icon.
         *  No string is used.
         */
    public QuitJButton(Icon i){
        this("",i);
    }

        /** Create a Quit button.
         */
    public QuitJButton(){
        this(label,null);
    }

        /** Exit the application.
         */
    public void actionPerformed(ActionEvent e){
        // Exit is prohibited from an applet.
        try{
            System.exit(0);
        }
        catch(RuntimeException ex){
        }
    }

    private static final String label = "Quit";
    {
        setBackground(Color.white);
    }
}
