Here is the complete text
package test;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.GridLayout;
import java.util.EventObject;
import javax.swing.JOptionPane;
public class AutoTest extends JFrame implements ActionListener
{
// instance variables
private javax.swing.JButton bExitButton;
public AutoTest() // This is the Constructor
{
setTitle("Test");
// center frame in screen
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
int width = 400;
int height = 400;
setBounds((d.width - width)/2, (d.height - height)/2, width, height);
// add a button to the frame
JPanel panel = new JPanel();
JButton bExitButton = new JButton("Exit");
System.out.println(bExitButton);
panel.add(bExitButton);
bExitButton.addActionListener(this);
Container contentPane = getContentPane();
panel.setLayout(new GridLayout(0, 1, 15, 1));
contentPane.add(panel);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
JOptionPane.showConfirmDialog(null,
"Are you sure you want to Exit?", "Alert",
JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
});
} // end of constructor
public void actionPerformed(java.awt.event.ActionEvent evt)
{
System.out.println("Inside actionPerformed routine");
Object source = evt.getSource();
System.out.println(source);
if (source == bExitButton)
{
System.out.println("Inside if statement");
JOptionPane.showConfirmDialog(null,
"Are you sure you want to Exit?", "Alert",
JOptionPane.OK_CANCEL_OPTION);
System.exit(0);
}
}
public static void main(String args[])
{
JFrame frame = new AutoTest();
frame.setVisible(true);
frame.setResizable(false);
}
} // end of class
Last edited by stonemonolith; Sep 13th, 2006 at 1:13 pm. Reason: forgot a command