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

public AncestorTree() {
    super("Ancestor Tree");
    setSize(400, 300);//www  .  ja  va2  s.com

    DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_SELF, "Myself"));
    addAncestors(top);
    m_model = new DefaultTreeModel(top);
    m_tree = new JTree(m_model);
    m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    m_tree.setShowsRootHandles(true);
    m_tree.setEditable(true);

    m_renderer = new IconCellRenderer();
    m_tree.setCellRenderer(m_renderer);
    m_editor = new IconCellEditor(m_tree);
    m_tree.setCellEditor(m_editor);
    m_tree.setInvokesStopCellEditing(true);

    m_tree.addMouseListener(new TreeExpander());

    JScrollPane s = new JScrollPane();
    s.getViewport().add(m_tree);
    getContentPane().add(s, BorderLayout.CENTER);

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

    setVisible(true);
}

From source file:MemComboBoxDemo.java

public MemComboBoxDemo() {
    super();//from w w w  . ja v a 2  s  . c o  m
    setSize(300, 100);
    getContentPane().setLayout(new BorderLayout());

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    p.add(new JLabel("Address"));

    urlComboBox.load("addresses.dat");
    ComboBoxListener lst = new ComboBoxListener();
    urlComboBox.addActionListener(lst);

    MemComboAgent agent = new MemComboAgent(urlComboBox);

    p.add(urlComboBox);
    getContentPane().add(p, BorderLayout.NORTH);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            urlComboBox.save("addresses.dat");
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    setVisible(true);
    urlComboBox.grabFocus();
}

From source file:LayeredPaneDemo3.java

public LayeredPaneDemo3() {
    super("Custom MDI: Part IV");
    setSize(570, 400);//from  ww  w.j a  v  a 2s.c  om
    getContentPane().setBackground(new Color(244, 232, 152));

    setLayeredPane(new MDIPane());

    ImageIcon ii = new ImageIcon("earth.jpg");
    InnerFrame[] frames = new InnerFrame[5];
    for (int i = 0; i < 5; i++) {
        frames[i] = new InnerFrame("InnerFrame " + i);
        frames[i].setBounds(50 + i * 20, 50 + i * 20, 200, 200);
        frames[i].getContentPane().add(new JScrollPane(new JLabel(ii)));
        getLayeredPane().add(frames[i]);
    }

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

    Dimension dim = getToolkit().getScreenSize();
    setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2);

    ImageIcon image = new ImageIcon("spiral.gif");
    setIconImage(image.getImage());
    addWindowListener(l);
    setVisible(true);
}

From source file:StocksTable3.java

public StocksTable3() {
    super("Stocks Table");
    setSize(600, 300);/*  w ww. j  a  v  a 2  s  .co  m*/

    m_data = new StockTableData();

    m_title = new JLabel(m_data.getTitle(), new ImageIcon("money.gif"), SwingConstants.LEFT);
    m_title.setFont(new Font("TimesRoman", Font.BOLD, 24));
    m_title.setForeground(Color.black);
    getContentPane().add(m_title, BorderLayout.NORTH);

    m_table = new JTable();
    m_table.setAutoCreateColumnsFromModel(false);
    m_table.setModel(m_data);

    for (int k = 0; k < StockTableData.m_columns.length; k++) {
        DefaultTableCellRenderer renderer = new ColoredTableCellRenderer();
        renderer.setHorizontalAlignment(StockTableData.m_columns[k].m_alignment);
        TableColumn column = new TableColumn(k, StockTableData.m_columns[k].m_width, renderer, null);
        m_table.addColumn(column);
    }

    JTableHeader header = m_table.getTableHeader();
    header.setUpdateTableInRealTime(false);

    JScrollPane ps = new JScrollPane();
    ps.getViewport().add(m_table);
    getContentPane().add(ps, BorderLayout.CENTER);

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

From source file:ClipArea.java

public ClipArea() {
    super();/*w w  w . ja v  a 2  s  .c o  m*/
    Container contentPane = getContentPane();

    canvas = new MyCanvas();
    contentPane.add(canvas);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, 2));
    clipButton = new JRadioButton("Clip", true);
    clipButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            canvas.clip = true;
            canvas.clipFurther = false;
            canvas.repaint();
        }
    });
    clipFurButton = new JRadioButton("Clip Further");
    clipFurButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            canvas.clipFurther = true;
            canvas.repaint();
        }
    });
    ButtonGroup group = new ButtonGroup();
    group.add(clipButton);
    group.add(clipFurButton);

    panel.add(clipButton);
    panel.add(clipFurButton);
    contentPane.add(BorderLayout.SOUTH, panel);

    // 4. Add a window listener to close the frame properly.
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    pack();
    setVisible(true);
}

From source file:LayeredPaneDemo4.java

public LayeredPaneDemo4() {
    super("Custom MDI: Part V");
    setSize(570, 400);//from www .  j a va 2s .c om
    getContentPane().setBackground(new Color(244, 232, 152));

    setLayeredPane(new MDIPane());

    ImageIcon ii = new ImageIcon("earth.jpg");
    InnerFrame[] frames = new InnerFrame[5];
    for (int i = 0; i < 5; i++) {
        frames[i] = new InnerFrame("InnerFrame " + i);
        frames[i].setBounds(50 + i * 20, 50 + i * 20, 200, 200);
        frames[i].getContentPane().add(new JScrollPane(new JLabel(ii)));
        getLayeredPane().add(frames[i]);
    }

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

    Dimension dim = getToolkit().getScreenSize();
    setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2);

    ImageIcon image = new ImageIcon("spiral.gif");
    setIconImage(image.getImage());
    addWindowListener(l);
    setVisible(true);
}

From source file:ConvolveApp.java

public ConvolveApp() {
    super();//from   w w w.  j av a  2s .c  o  m
    Container container = getContentPane();

    displayPanel = new CPanel();
    container.add(displayPanel);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(2, 2));
    panel.setBorder(new TitledBorder("Click a Button to Perform the Associated Operation and Reset..."));

    sharpenButton = new JButton("Sharpen");
    sharpenButton.addActionListener(new ButtonListener());
    blurringButton = new JButton("Blur");
    blurringButton.addActionListener(new ButtonListener());
    edButton = new JButton("Edge Detect");
    edButton.addActionListener(new ButtonListener());
    resetButton = new JButton("Reset");
    resetButton.addActionListener(new ButtonListener());

    panel.add(sharpenButton);
    panel.add(blurringButton);
    panel.add(edButton);
    panel.add(resetButton);

    container.add(BorderLayout.SOUTH, panel);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    setSize(displayPanel.getWidth(), displayPanel.getHeight() + 10);
    setVisible(true);
}

From source file:KjellDirdalNotepad.java

public KjellDirdalNotepad() {
    menuBar.add(fileMenu);/*from w  w w.j a  v a2  s .  c  o m*/
    menuBar.add(new WindowMenu(desktop));
    fileMenu.add(newMenu);
    setJMenuBar(menuBar);
    setTitle("MDI Test");
    scrollPane.getViewport().add(desktop);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(scrollPane, BorderLayout.CENTER);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    newMenu.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            desktop.add(new TextFrame());
        }
    });

}

From source file:test.buddhabrot.BuddhabrotApp.java

public BuddhabrotApp(final GridNode node) throws HeadlessException {
    super();/*from  ww w .j  a  va 2  s. co m*/
    setSize(WIDTH, HEIGHT);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {

            try {
                if (future != null) {

                    if (!future.isJobFinished()) {
                        log.info("Cancelling Job... wait");
                        setTitle("Cancelling Job - WAIT");
                        if (!future.cancel()) {
                            log.warn("Cancel Failed");
                        }
                    }
                }

                node.shutdown();
                // Give time to send termination message
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            System.exit(0);
        }

    });

    setVisible(true);

    // create off-screen buffer
    Graphics g = image.getGraphics();
    g.setColor(Color.black);
    g.fillRect(0, 0, WIDTH, HEIGHT);
    repaint();
}

From source file:org.jcodec.player.app.PlayerMain.java

public PlayerMain(URL url) throws IOException {
    JFrame frame = new JFrame("Player");

    vo = new SwingVO();
    frame.getContentPane().add(vo, BorderLayout.CENTER);

    // Finish setting up the frame, and show it.
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//w ww.ja v  a2s. com
        }
    });
    vo.setVisible(true);

    File cacheWhere = new File(System.getProperty("user.home"), "Library/JCodec");
    FileUtils.forceMkdir(cacheWhere);

    HttpMedia http = new HttpMedia(url, cacheWhere);

    final HttpPacketSource videoTrack = http.getVideoTrack();
    video = new JCodecVideoSource(videoTrack);

    List<HttpPacketSource> audioTracks = http.getAudioTracks();
    AudioSource[] audio = new AudioSource[audioTracks.size()];
    for (int i = 0; i < audioTracks.size(); i++) {
        audio[i] = new JCodecAudioSource(audioTracks.get(i));
    }
    mixer = new AudioMixer(2, audio);

    player = new Player(video, mixer, vo, new JSoundAudioOut());

    frame.addKeyListener(this);

    frame.pack();
    frame.setVisible(true);
    frame.setSize(new Dimension(768, 596));

    player.play();
}