9
Using anonymous classes
- import java.awt.Frame;
- import java.awt.event.*;
- public class SimpleWindow6 {
- static Frame appwin;
- public static void main(String[] args) {
- appwin = new Frame("Application");
- appwin.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
- appwin.setBounds(100, 100, 300, 200);
- appwin.setVisible(true);
- }
- }
- import java.awt.Frame;
- import java.awt.event.*;
- @SuppressWarnings("serial")
- public class SimpleWindow7 extends Frame {
- static SimpleWindow7 appwin;
- public static void main(String[] args) {
- appwin = new SimpleWindow7("Application");
- appwin.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.out.println("Exit 1");
- System.exit(0);
- }
- });
- }
- SimpleWindow7(String title) {
- super(title);
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.out.println("Exit 2");
- // System.exit(0);
- }
- });
- setBounds(100, 100, 300, 200);
- setVisible(true);
- }
- }
- import java.awt.Frame;
- import java.awt.event.*;
- @SuppressWarnings("serial")
- public class SimpleWindow8 extends Frame {
- static SimpleWindow8 appwin;
- public static void main(String[] args) {
- appwin = new SimpleWindow8("Application");
- appwin.setVisible(true);
- }
- SimpleWindow8(String title) {
- super(title);
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
- setBounds(100, 100, 300, 200);
- }
- }
Comments