Where to put windowClosing Event
Hi Friends,
I need to add window Closing Event to following code to close the program when clicked close button.
<code>
import java.awt.*;
import java.awt.event.*;
public class App1 extends Frame implements ItemListener
{
private Choice choice1;
Label label1 = new Label("Make a Choice!");
App1()
{
super("Sample Choice");
add(label1, BorderLayout.NORTH);
choice1 = new Choice();
choice1.addItem("One");
choice1.addItem("Two");
choice1.addItem("Three");
choice1.addItemListener(this);
add(choice1, BorderLayout.CENTER);
pack();
setSize(200, getPreferredSize().height);
setLocation(25, 25);
setVisible(true);
}
public void itemStateChanged(ItemEvent ie)
{
String state = "Deselected";
if(ie.getStateChange() == ItemEvent.SELECTED)
{
state = "Selected";
}
label1.setText(ie.getItem() + " " +state);
}
public static void main(String args[])
{
new App1();
}
}
</code>
I need to insert the code,
<code>
addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent e) {System.exit(0);}});
</code>
into the above program.
Please help me to add this code into my program.