Example usage for java.awt.event WindowAdapter WindowAdapter

List of usage examples for java.awt.event WindowAdapter WindowAdapter

Introduction

In this page you can find the example usage for java.awt.event WindowAdapter WindowAdapter.

Prototype

WindowAdapter

Source Link

Usage

From source file:JMFTest.java

JMFTest() {
    Player _player;/*  w  w w.j a  v  a  2s  .c  o  m*/
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            _player.stop();
            _player.deallocate();
            _player.close();
            System.exit(0);
        }
    });
    setExtent(0, 0, 320, 260);
    JPanel panel = (JPanel) getContentPane();
    panel.setLayout(new BorderLayout());
    String mediaFile = "vfw://1";
    try {
        MediaLocator mlr = new MediaLocator(mediaFile);
        _player = Manager.createRealizedPlayer(mlr);
        if (_player.getVisualComponent() != null)
            panel.add("Center", _player.getVisualComponent());
        if (_player.getControlPanelComponent() != null)
            panel.add("South", _player.getControlPanelComponent());
    } catch (Exception e) {
        System.err.println("Got exception " + e);
    }
}

From source file:DebugWinTest.java

public DebugWinTest() {
    setTitle("DebugWinTest");
    setSize(100, 100);/* w  ww.  j  av  a  2 s  .co m*/
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    JPanel pane = new JPanel();

    pane.add(aButton);
    aButton.addActionListener(this);

    getContentPane().add(pane);
}

From source file:ListTest.java

public ListTest() {
    setTitle("ListTest: Press control to multi-select");
    setSize(400, 300);//w  ww  .j av a 2  s  .co  m
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    String[] words = { "quick", "brown", "hungry", "wild", "silent", "huge" };

    JList wordList = new JList(words);
    JScrollPane scrollPane = new JScrollPane(wordList);

    JPanel p = new JPanel();
    p.add(scrollPane);
    wordList.addListSelectionListener(this);

    getContentPane().add(p, "South");
    getContentPane().add(label, "Center");
}

From source file:FontComboBox.java

public FontComboBox() {
    setTitle("ComboBoxTest");
    setSize(300, 200);// w  ww .j  a va 2  s . c  o m
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    fontComboBox = new JComboBox();
    fontComboBox.setEditable(true);
    fontComboBox.addItem("Serif");
    fontComboBox.addItem("SansSerif");
    fontComboBox.addItem("Monospaced");
    fontComboBox.addItem("Dialog");
    fontComboBox.addItem("DialogInput");
    fontComboBox.addActionListener(this);

    JPanel p = new JPanel();
    p.add(fontComboBox);
    getContentPane().add(p, "North");
    getContentPane().add(fontLabel, "Center");
}

From source file:ModalFrameUtil.java

public static void showAsModal(final Frame frame, final Frame owner) {
    frame.addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
            owner.setEnabled(false);// w  ww  .j a  v a 2  s  .  co m
        }

        public void windowClosing(WindowEvent e) {
            owner.setEnabled(true);
            frame.removeWindowListener(this);
        }

        public void windowClosed(WindowEvent e) {
            owner.setEnabled(true);
            frame.removeWindowListener(this);
        }
    });

    owner.addWindowListener(new WindowAdapter() {
        public void windowActivated(WindowEvent e) {
            if (frame.isShowing()) {
                frame.setExtendedState(JFrame.NORMAL);
                frame.toFront();
            } else {
                owner.removeWindowListener(this);
            }
        }
    });

    frame.setVisible(true);
    try {
        new EventPump(frame).start();
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    }
}

From source file:org.marekasf.troughput.XYHistogramChart.java

public static void display(final AdaptiveHistogram h, final String title) {

    final XYHistogramChart demo = new XYHistogramChart(h, title);
    demo.pack();//from w  w w  .jav a  2 s.com
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);
    final Semaphore semaphore = new Semaphore(0);
    demo.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(final WindowEvent we) {
            semaphore.release();
        }
    });
    try {
        semaphore.acquire();
    } catch (final InterruptedException e) {
        //
    }
}

From source file:LongListTest.java

public LongListTest() {
    setTitle("LongListTest");
    setSize(400, 300);//from  w w  w  .ja  v a 2s  .c  o  m
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    JList wordList = new JList(new WordListModel(300000));
    wordList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    wordList.setFixedCellWidth(50);
    wordList.setFixedCellHeight(15);

    JScrollPane scrollPane = new JScrollPane(wordList);

    JPanel p = new JPanel();
    p.add(scrollPane);
    wordList.addListSelectionListener(this);

    getContentPane().add(p, "Center");

    getContentPane().add(label, "North");
}

From source file:SimpleList.java

public SimpleList() {
    super("Simple Swing List");
    setSize(500, 240);/*  ww  w. j  av  a  2 s  .  c  om*/

    String[] item = { "First", "Second", "Third" };

    list = new JList(item);

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.getViewport().add(list);
    getContentPane().add(scrollPane, BorderLayout.CENTER);

    WindowListener exit = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(exit);

    setVisible(true);
}

From source file:HtmlButtons.java

public HtmlButtons() {
    super("HTML Buttons");
    setSize(400, 300);/*from w w  w.j  a  v  a 2s  .  co  m*/

    getContentPane().setLayout(new FlowLayout());

    String htmlText = "<html><p><font color=\"#800080\" " + "size=\"4\" face=\"Verdana\">JButton</font> </p>"
            + "<font size=\"2\"><em>" + "with HTML text</em></font></html>";
    JButton btn = new JButton(htmlText);
    getContentPane().add(btn);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}

From source file:DocumentListenerDemo.java

public DocumentListenerDemo() {
    setTitle("TextTest");
    setSize(500, 200);//from   w  ww  .j  av a  2 s . co  m
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    Container contentPane = getContentPane();

    JPanel p = new JPanel();

    p.add(hourField);
    hourField.getDocument().addDocumentListener(this);

    p.add(minuteField);
    minuteField.getDocument().addDocumentListener(this);

    contentPane.add(p, "Center");
    contentPane.add(label, "North");

}