Example usage for javax.swing JFrame addWindowListener

List of usage examples for javax.swing JFrame addWindowListener

Introduction

In this page you can find the example usage for javax.swing JFrame addWindowListener.

Prototype

public synchronized void addWindowListener(WindowListener l) 

Source Link

Document

Adds the specified window listener to receive window events from this window.

Usage

From source file:IconPaint.java

public static void main(String[] args) {
    Image starImage = Toolkit.getDefaultToolkit().getImage(IconPaint.iconFile);

    IconPanel starPanel = new IconPanel(starImage);

    JFrame f = new JFrame("Icon");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from w  w  w .  jav  a 2 s . c o m*/
        }
    });

    f.getContentPane().add(starPanel, BorderLayout.CENTER);
    f.setSize(new Dimension(550, 200));
    f.setVisible(true);
}

From source file:EditorPaneExample1.java

public static void main(String[] args) {
    try {//from  ww w.  j  a v a2s  . c  o m
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new EditorPaneExample1();

    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    f.setSize(500, 400);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setSize(300, 200);/*  w ww  . j a  v  a 2  s  . c  o m*/
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    Container contentPane = frame.getContentPane();
    contentPane.add(new Main());

    frame.setVisible(true);
}

From source file:ColorGradient.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from   ww w.  j  av a2  s .  co  m*/
        }
    });
    ColorGradient g = new ColorGradient();
    g.init();

    f.setContentPane(g);
    f.setSize(600, 200);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    JFrame frame = new JFrame();
    frame.addWindowListener(new WindowListener() {
        @Override//  w  w w  .  j a va  2 s  .  c o m
        public void windowOpened(WindowEvent e) {
            System.out.println("JFrame has  been  made visible first  time");
        }

        @Override
        public void windowClosing(WindowEvent e) {
            System.out.println("JFrame is closing.");
        }

        @Override
        public void windowClosed(WindowEvent e) {
            System.out.println("JFrame is closed.");
        }

        @Override
        public void windowIconified(WindowEvent e) {
            System.out.println("JFrame is  minimized.");
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
            System.out.println("JFrame is restored.");
        }

        @Override
        public void windowActivated(WindowEvent e) {
            System.out.println("JFrame is activated.");
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
            System.out.println("JFrame is deactivated.");
        }
    });

    // Use the WindowAdapter class to intercept only the window closing event
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            System.out.println("JFrame is closing.");
        }
    });

}

From source file:GeneralPathDemo.java

public static void main(String s[]) {

    JFrame f = new JFrame("Odd Shape");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);// www.  j a  va2  s.c o  m
        }
    });

    f.getContentPane().add(new GeneralPathDemo());
    f.setSize(new Dimension(350, 200));
    f.setVisible(true);
}

From source file:BoxLayoutPane.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*  w w w.  j a v a 2s. c  om*/
        }
    });

    f.setContentPane(new BoxLayoutPane());
    f.pack();
    f.setVisible(true);
}

From source file:LineStyles.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//  ww  w  .  ja  v  a2  s .  co  m
        }
    });
    f.setContentPane(new LineStyles());
    f.setSize(450, 200);
    f.setVisible(true);
}

From source file:org.OpenNI.Samples.UserTracker.UserTrackerApplication.java

public static void main(String s[]) {
    JFrame f = new JFrame("OpenNI User Tracker");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from  www.  j  a v  a  2  s. c o  m*/
        }
    });
    UserTrackerApplication app = new UserTrackerApplication(f);

    app.viewer = new UserTracker();
    f.add("Center", app.viewer);
    f.pack();
    f.setVisible(true);
    app.run();
}

From source file:NotHelloWorldPanel.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setTitle("NotHelloWorld");
    frame.setSize(300, 200);// ww  w .  j a va  2 s  .co m
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    Container contentPane = frame.getContentPane();
    contentPane.add(new NotHelloWorldPanel());

    frame.show();
}