Java Reference
In-Depth Information
{
public ConfirmWindow()
{
setSize(SMALL_WIDTH, SMALL_HEIGHT);
getContentPane().setBackground(Color.YELLOW);
setLayout( new BorderLayout());
JLabel confirmLabel = new JLabel(
"Are you sure you want to exit?");
add(confirmLabel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(Color.ORANGE);
buttonPanel.setLayout( new FlowLayout());
JButton exitButton = new JButton("Yes");
exitButton.addActionListener(this);
buttonPanel.add(exitButton);
JButton cancelButton = new JButton("No");
cancelButton.addActionListener( this );
buttonPanel.add(cancelButton);
add(buttonPanel, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand();
if (actionCommand.equals("Yes"))
System.exit(0);
else if (actionCommand.equals("No"))
dispose();// Destroys only the ConfirmWindow .
else
System.out.println(
"Unexpected Error in Confirm Window.");
}
} // End of inner class ConfirmWindow
public static void main(String[] args)
{
WindowListenerDemo3 demoWindow =
new WindowListenerDemo3();
demoWindow.setVisible( true );
}
Search WWH ::




Custom Search