9

Using anonymous classes

  1. import java.awt.Frame;
  2. import java.awt.event.*;
  3.  
  4. public class SimpleWindow6 {
  5.  
  6.     static Frame appwin;
  7.  
  8.     public static void main(String[] args) {
  9.         appwin = new Frame("Application");
  10.         appwin.addWindowListener(new WindowAdapter() {
  11.             public void windowClosing(WindowEvent e) {
  12.                 System.exit(0);
  13.             }
  14.         });
  15.         appwin.setBounds(100, 100, 300, 200);
  16.         appwin.setVisible(true);
  17.     }
  18. }
  1. import java.awt.Frame;
  2. import java.awt.event.*;
  3.  
  4. @SuppressWarnings("serial")
  5. public class SimpleWindow7 extends Frame {
  6.  
  7.     static SimpleWindow7 appwin;
  8.  
  9.     public static void main(String[] args) {
  10.         appwin = new SimpleWindow7("Application");
  11.         appwin.addWindowListener(new WindowAdapter() {
  12.             public void windowClosing(WindowEvent e) {
  13.                 System.out.println("Exit 1");
  14.                 System.exit(0);
  15.             }
  16.         });
  17.  
  18.     }
  19.    
  20.     SimpleWindow7(String title) {
  21.         super(title);
  22.         addWindowListener(new WindowAdapter() {
  23.             public void windowClosing(WindowEvent e) {
  24.                 System.out.println("Exit 2");
  25. //              System.exit(0);
  26.             }
  27.         });
  28.         setBounds(100, 100, 300, 200);
  29.         setVisible(true);
  30.     }
  31. }
  1. import java.awt.Frame;
  2. import java.awt.event.*;
  3.  
  4. @SuppressWarnings("serial")
  5. public class SimpleWindow8 extends Frame {
  6.  
  7.     static SimpleWindow8 appwin;
  8.  
  9.     public static void main(String[] args) {
  10.         appwin = new SimpleWindow8("Application");
  11.         appwin.setVisible(true);
  12.     }
  13.  
  14.     SimpleWindow8(String title) {
  15.         super(title);
  16.         addWindowListener(new WindowAdapter() {
  17.             public void windowClosing(WindowEvent e) {
  18.                 System.exit(0);
  19.             }
  20.         });
  21.         setBounds(100, 100, 300, 200);
  22.     }
  23. }

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].