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

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

    JPanel p = new JPanel();
    p.add(bold);
    p.add(italic);
    bold.addActionListener(this);
    italic.addActionListener(this);
    getContentPane().add(p, "South");
    getContentPane().add(fontLabel, "Center");
}

From source file:HtmlLabel.java

public HtmlLabel() {
    super("HTML Buttons");
    setSize(400, 300);//from  www.  j  a v  a2 s. c  om

    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>";
    JLabel btn = new JLabel(htmlText);
    getContentPane().add(btn);

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

From source file:LayeredPaneDemo.java

public LayeredPaneDemo() {
    super("");
    setSize(570, 400);/* www  . j av a 2  s .com*/
    getContentPane().setBackground(new Color(244, 232, 152));

    getLayeredPane().setOpaque(true);

    JButton[] frames = new JButton[5];
    for (int i = 0; i < 5; i++) {
        frames[i] = new JButton("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);
        }
    };

    addWindowListener(l);
    setVisible(true);
}

From source file:MainClass.java

public MainClass() {
    this.setSize(275, 100);
    this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    ClickListener cl = new ClickListener();

    JPanel panel1 = new JPanel();

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            exitButton.doClick();/*from w w w.ja  va  2  s .c  o  m*/
        }
    });

    button1.addActionListener(cl);
    panel1.add(button1);

    exitButton.addActionListener(cl);
    panel1.add(exitButton);
    this.add(panel1);

    this.setVisible(true);
}

From source file:BufferedImageMouseDrag.java

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

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

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

From source file:Main.java

public Main() {
    this.setLayout(new GridLayout(0, 1));
    this.add(new JLabel("Dialog event test.", JLabel.CENTER));
    this.add(new JButton(new AbstractAction("Close") {
        @Override//from  ww w .j a  va2 s .  c  o m
        public void actionPerformed(ActionEvent e) {
            Main.this.setVisible(false);
            Main.this.dispatchEvent(new WindowEvent(Main.this, WindowEvent.WINDOW_CLOSING));
        }
    }));
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            System.out.println(e.paramString());
        }
    });
}

From source file:EditorDropTarget3.java

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

    final JFrame f = new JFrame("JEditor Pane Drop Target Example 3");

    final JEditorPane pane = new JEditorPane();

    // Add a drop target to the JEditorPane
    EditorDropTarget3 target = new EditorDropTarget3(pane);

    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });

    JPanel panel = new JPanel();
    final JCheckBox editable = new JCheckBox("Editable");
    editable.setSelected(true);
    panel.add(editable);
    editable.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pane.setEditable(editable.isSelected());
        }
    });

    final JCheckBox enabled = new JCheckBox("Enabled");
    enabled.setSelected(true);
    panel.add(enabled);
    enabled.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pane.setEnabled(enabled.isSelected());
        }
    });

    f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER);
    f.getContentPane().add(panel, BorderLayout.SOUTH);
    f.setSize(500, 400);
    f.setVisible(true);
}

From source file:TextEditFrame.java

public TextEditFrame() {
    setTitle("TextEditTest");
    setSize(500, 300);//from www  . j av  a 2 s  .  com
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    Container contentPane = getContentPane();

    JPanel panel = new JPanel();

    JButton replaceButton = new JButton("Replace");
    panel.add(replaceButton);
    replaceButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            String from = fromField.getText();
            int start = textArea.getText().indexOf(from);
            if (start >= 0 && from.length() > 0)
                textArea.replaceRange(toField.getText(), start, start + from.length());
        }
    });

    panel.add(fromField);

    panel.add(new JLabel("with"));

    panel.add(toField);

    contentPane.add(panel, "South");
    contentPane.add(scrollPane, "Center");
}

From source file:GrabAndDragDemo.java

public GrabAndDragDemo() {
    super("Grab and drag Demo");
    ImageIcon ii = new ImageIcon("largeJava2sLogo.jpg");
    JScrollPane jsp = new JScrollPane(new GrabAndScrollLabel(ii));
    getContentPane().add(jsp);/*from w  w w  .j  av a2 s.c o m*/
    setSize(300, 250);
    setVisible(true);

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

From source file:ValidationTestFrame.java

public ValidationTestFrame() {
    setTitle("ValidationTest");
    setSize(300, 200);// www.  j a va  2s  .  com
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    Container contentPane = getContentPane();

    JPanel p = new JPanel();
    intFiled = new IntTextField(12, 3);
    p.add(intFiled);
    intFiled.getDocument().addDocumentListener(this);

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