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:EditorPaneExample3.java

public static void main(String[] args) {
    try {//from w w  w  . j  av  a2 s .  c om
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

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

From source file:MulticastEvent.java

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

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

    frame.show();
}

From source file:PrintUIWindow.java

public static void main(String args[]) {
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    JFrame f = new JFrame("Print UI Example");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//  ww  w .ja  v a  2s  .  c o  m
        }
    });
    JTextArea text = new JTextArea(50, 20);
    for (int i = 1; i <= 50; i++) {
        text.append("Line " + i + "\n");
    }
    JScrollPane pane = new JScrollPane(text);
    pane.setPreferredSize(new Dimension(250, 200));
    f.add("Center", pane);
    JButton printButton = new JButton("Print This Window");
    printButton.addActionListener(new PrintUIWindow(f));
    f.add("South", printButton);
    f.pack();
    f.setVisible(true);
}

From source file:FontPanel.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setTitle("NotHelloWorld2");
    frame.setSize(350, 200);//from w  w  w  .  j a  va  2s.com
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    Container contentPane = frame.getContentPane();
    contentPane.add(new FontPanel());

    frame.show();
}

From source file:Starry.java

public static void main(String[] args) {
    Image starry = new ImageIcon("yourFile.gif").getImage();

    StarPanel starPanel = new StarPanel(starry);

    JFrame f = new JFrame("Starry");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from  w  ww . ja va  2s  .c o  m
        }
    });

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

From source file:SketchPanel.java

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

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

    frame.show();
}

From source file:WindowEventHandler.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Swing Frame");

    JLabel label = new JLabel("This is a Swing frame", JLabel.CENTER);

    frame.add(label);/*from  w ww  .j  a  va  2  s. com*/

    frame.addWindowListener(new WindowEventHandler());
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.setSize(350, 200); // width=350, height=200
    frame.setVisible(true); // Display the frame
}

From source file:Clock.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from  w  w  w .j  ava2  s. c  om*/
        }
    });
    Clock c = new Clock();
    f.getContentPane().add("Center", c);
    f.pack();
    f.setSize(new Dimension(300, 300));
    f.show();

}

From source file:MainClass.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new MainClass());

    //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.addWindowListener(new FrameListener());

    frame.setSize(200, 200);/* w w w  . j  a  v  a2  s.  c  o m*/
    frame.setVisible(true);
}

From source file:Paints.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from w  w w .j a  va 2  s . c  o  m*/
        }
    });
    f.setContentPane(new Paints());
    f.setSize(800, 375);
    f.setVisible(true);
}