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

public DragTest() {
    super("Drag Test");
    setSize(200, 150);/*from   w  ww .  ja v  a 2  s .  co m*/
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            System.exit(0);
        }
    });
    jl = new JList(items);
    jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    getContentPane().add(new JScrollPane(jl), BorderLayout.CENTER);

    ds = new DragSource();
    DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer(jl, DnDConstants.ACTION_COPY, this);
    setVisible(true);
}

From source file:GUI.MainJF.java

private void initializeComponent() {

    this.addWindowListener(new WindowAdapter() {

        public void windowActivated(WindowEvent e) {
            LlenarTabla();/*from  www  .  ja va 2s  . c  o  m*/
        }
    });
}

From source file:de.dakror.virtualhub.client.dialog.ChooseCatalogDialog.java

public static void show(ClientFrame frame, final JSONArray data) {
    final JDialog dialog = new JDialog(frame, "Katalog whlen", true);
    dialog.setSize(400, 300);//ww w  .j  a  va 2s . c  o m
    dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            Client.currentClient.disconnect();
            System.exit(0);
        }
    });

    JPanel contentPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
    dialog.setContentPane(contentPane);
    DefaultListModel dlm = new DefaultListModel();
    for (int i = 0; i < data.length(); i++) {
        try {
            dlm.addElement(data.getJSONObject(i).getString("name"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    final JList catalogs = new JList(dlm);
    catalogs.setDragEnabled(false);
    catalogs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JScrollPane jsp = new JScrollPane(catalogs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jsp.setPreferredSize(new Dimension(396, 200));
    contentPane.add(jsp);

    JPanel mods = new JPanel(new GridLayout(1, 2));
    mods.setPreferredSize(new Dimension(50, 22));
    mods.add(new JButton(new AbstractAction("+") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            String name = JOptionPane.showInputDialog(dialog,
                    "Bitte geben Sie den Namen des neuen Katalogs ein.", "Katalog hinzufgen",
                    JOptionPane.PLAIN_MESSAGE);
            if (name != null && name.length() > 0) {
                DefaultListModel dlm = (DefaultListModel) catalogs.getModel();
                for (int i = 0; i < dlm.getSize(); i++) {
                    if (dlm.get(i).toString().equals(name)) {
                        JOptionPane.showMessageDialog(dialog,
                                "Es existert bereits ein Katalog mit diesem Namen!",
                                "Katalog bereits vorhanden!", JOptionPane.ERROR_MESSAGE);
                        actionPerformed(e);
                        return;
                    }
                }

                try {
                    dlm.addElement(name);
                    JSONObject o = new JSONObject();
                    o.put("name", name);
                    o.put("sources", new JSONArray());
                    o.put("tags", new JSONArray());
                    data.put(o);
                    Client.currentClient.sendPacket(new Packet0Catalogs(data));
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    }));
    mods.add(new JButton(new AbstractAction("-") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (catalogs.getSelectedIndex() != -1) {
                if (JOptionPane.showConfirmDialog(dialog,
                        "Sind Sie sicher, dass Sie diesen\r\nKatalog unwiderruflich lschen wollen?",
                        "Katalog lschen", JOptionPane.YES_NO_CANCEL_OPTION,
                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
                    DefaultListModel dlm = (DefaultListModel) catalogs.getModel();
                    data.remove(catalogs.getSelectedIndex());
                    dlm.remove(catalogs.getSelectedIndex());
                    try {
                        Client.currentClient.sendPacket(new Packet0Catalogs(data));
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    }));

    contentPane.add(mods);

    JLabel l = new JLabel("");
    l.setPreferredSize(new Dimension(396, 14));
    contentPane.add(l);

    JSeparator sep = new JSeparator(JSeparator.HORIZONTAL);
    sep.setPreferredSize(new Dimension(396, 10));
    contentPane.add(sep);

    JPanel buttons = new JPanel(new GridLayout(1, 2));
    buttons.setPreferredSize(new Dimension(396, 22));
    buttons.add(new JButton(new AbstractAction("Abbrechen") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            Client.currentClient.disconnect();
            System.exit(0);
        }
    }));
    buttons.add(new JButton(new AbstractAction("Katalog whlen") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (catalogs.getSelectedIndex() != -1) {
                try {
                    Client.currentClient
                            .setCatalog(new Catalog(data.getJSONObject(catalogs.getSelectedIndex())));
                    Client.currentClient.frame.setTitle("- " + Client.currentClient.getCatalog().getName());
                    dialog.dispose();
                } catch (JSONException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }));

    dialog.add(buttons);

    dialog.setLocationRelativeTo(frame);
    dialog.setResizable(false);
    dialog.setVisible(true);
}

From source file:LayeredPaneDemo.java

public LayeredPaneDemo() {
    super("Custom MDI: Part II");
    setSize(570, 400);/*from w w w . ja va 2s . c  o m*/
    getContentPane().setBackground(new Color(244, 232, 152));

    getLayeredPane().setOpaque(true);

    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);
        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:BufferedImageThread.java

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

    canvas = new AnimationCanvas();
    container.add(canvas);

    startButton = new JButton("Start Animation");
    startButton.addActionListener(new ButtonListener());
    stopButton = new JButton("Stop Animation");
    stopButton.addActionListener(new ButtonListener());
    JPanel panel = new JPanel();
    panel.add(startButton);
    panel.add(stopButton);
    container.add(BorderLayout.SOUTH, panel);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    setSize(450, 425);
    setVisible(true);
}

From source file:de.bley.word.menu.ClickedGuiMenu.java

/**
 * Initialisiuerung der Komponenten.// w w  w.j a  va  2  s  .c o m
 */
private void setup() {
    path = PropertieManager.getInstance().getZuordnung().getPath().getFilepath();
    initComponents();
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            if (!jEditorPane1.getText().equals("")) {

                if (!jEditorPane1.getText()
                        .equals(PropertieManager.getInstance().getZuordnung().getReader().readFile(path))) {
                    int confirmed = JOptionPane.showConfirmDialog(null, "Speichern der Daten?", "Beenden",
                            JOptionPane.YES_NO_OPTION);

                    if (confirmed == JOptionPane.YES_OPTION) {
                        saveData();
                        dispose();
                    }
                }
            }
        }
    });
    read();
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }

    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | javax.swing.UnsupportedLookAndFeelException ex) {
        log.debug("NewJFrame" + ex);
    }

}

From source file:MenuDemo.java

public MenuDemo() {
    super("Basic text editor");
    setSize(450, 350);/*from w ww.j ava 2s.co  m*/

    fontArray = new Font[FontNames.length];
    for (int i = 0; i < FontNames.length; i++)
        fontArray[i] = new Font(FontNames[i], Font.PLAIN, 12);

    JMenuBar menuBar = createMenuBar();
    setJMenuBar(menuBar);

    fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(new File("."));

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

    updateMonitor();
    setVisible(true);
}

From source file:edu.pdi2.visual.extradialogs.SignatureDialog.java

private void initGUI() {
    try {//from www  .  ja v a2  s . c o m
        {
            getContentPane().setLayout(null);
            this.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent evt) {
                    thisWindowClosing(evt);
                }
            });
            {
                chartpanel = new ChartPanel(signatureG);
                getContentPane().add(chartpanel);
                chartpanel.setBorder(BorderFactory.createTitledBorder(""));
                chartpanel.setBounds(6, 5, 386, 211);
            }
        }
        this.setSize(410, 254);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ToolbarDemo.java

public ToolbarDemo() {
    super("Toolbars & actions");
    setSize(450, 350);// w ww  . j  av  a  2  s .c om

    fonts = new Font[FontNames.length];
    for (int i = 0; i < FontNames.length; i++)
        fonts[i] = new Font(FontNames[i], Font.PLAIN, 12);

    JMenuBar menuBar = createMenuBar();
    setJMenuBar(menuBar);

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

    updateMonitor();
    setVisible(true);
}

From source file:FramewithComponents.java

public FramewithComponents() {
    super("JLayeredPane Demo");
    setSize(256, 256);/*from  ww w.j  a  v a 2 s . c  o  m*/

    JPanel content = new JPanel();
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.setOpaque(false);

    JLabel label1 = new JLabel("Username:");
    label1.setForeground(Color.white);
    content.add(label1);

    JTextField field = new JTextField(15);
    content.add(field);

    JLabel label2 = new JLabel("Password:");
    label2.setForeground(Color.white);
    content.add(label2);

    JPasswordField fieldPass = new JPasswordField(15);
    content.add(fieldPass);

    getContentPane().setLayout(new FlowLayout());
    getContentPane().add(content);
    ((JPanel) getContentPane()).setOpaque(false);

    ImageIcon earth = new ImageIcon("largeJava2sLogo.png");
    JLabel backlabel = new JLabel(earth);
    getLayeredPane().add(backlabel, new Integer(Integer.MIN_VALUE));
    backlabel.setBounds(0, 0, earth.getIconWidth(), earth.getIconHeight());

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

    setVisible(true);
}