How to close AWT Window in Java


The object of a TextArea class is a multi line region that presentations content. It permits the altering of different line content. It acquires TextComponent class.

AWT TextArea Class Declaration

  1. public class TextArea extends TextComponent  

Java AWT TextArea Example

  1. import java.awt.*;  
  2. import java.awt.event.*;  
  3. public class AdapterExample extends WindowAdapter{  
  4.     Frame f;  
  5.     AdapterExample(){  
  6.         f=new Frame();  
  7.         f.addWindowListener(this);  
  8.           
  9.         f.setSize(400,400);  
  10.         f.setLayout(null);  
  11.         f.setVisible(true);  
  12.     }  
  13. public void windowClosing(WindowEvent e) {  
  14.     f.dispose();  
  15. }  
  16. public static void main(String[] args) {  
  17.     new AdapterExample();  
  18. }  
  19. }  

Close AWT Window Example 3: implementing WindowListener

  1. import java.awt.*;  
  2. import java.awt.event.WindowEvent;  
  3. import java.awt.event.WindowListener;  
  4. public class WindowExample extends Frame implements WindowListener{  
  5.     WindowExample(){  
  6.         addWindowListener(this);  
  7.           
  8.         setSize(400,400);  
  9.         setLayout(null);  
  10.         setVisible(true);  
  11.     }  
  12.       
  13. public static void main(String[] args) {  
  14.     new WindowExample();  
  15. }  
  16. public void windowActivated(WindowEvent e) {}  
  17. public void windowClosed(WindowEvent e) {}  
  18. public void windowClosing(WindowEvent e) {  
  19.     dispose();  
  20. }  
  21. public void windowDeactivated(WindowEvent e) {}  
  22. public void windowDeiconified(WindowEvent e) {}  
  23. public void windowIconified(WindowEvent e) {}  
  24. public void windowOpened(WindowEvent arg0) {}  
  25. }  





javacodegeeks is optimized for learning.© javacodegeeks .
All Right Reserved and you agree to have read and accepted our term and condition