Wednesday, 23 April 2014

How to close the window in awt

By Using windowLister we can close the window.

   myFrame.addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent we){
         System.exit(0);
      }
   });


import java.awt.*;
import java.awt.event.*;

class WindowClose{
 Frame myFrame;
 
 void display(){
  myFrame = new Frame("Add Popup Menu");
  myFrame.setVisible(true);
  myFrame.setSize(250, 250);
  
  myFrame.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent we){
    System.exit(0);
    }
  });
 }
 public static void main(String args[]){
  ComponentAdd obj1 = new ComponentAdd();
  obj1.display();
 }
}

Output




 
Once you click on the close button window is closed.
 








                                                             Home

No comments:

Post a Comment