Search in sources :

Example 36 with WindowAdapter

use of java.awt.event.WindowAdapter in project jmonkeyengine by jMonkeyEngine.

the class TestSafeCanvas method main.

public static void main(String[] args) throws InterruptedException {
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);
    final TestSafeCanvas app = new TestSafeCanvas();
    app.setPauseOnLostFocus(false);
    app.setSettings(settings);
    app.createCanvas();
    app.startCanvas(true);
    JmeCanvasContext context = (JmeCanvasContext) app.getContext();
    Canvas canvas = context.getCanvas();
    canvas.setSize(settings.getWidth(), settings.getHeight());
    Thread.sleep(3000);
    JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            app.stop();
        }
    });
    frame.getContentPane().add(canvas);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    Thread.sleep(3000);
    frame.getContentPane().remove(canvas);
    Thread.sleep(3000);
    frame.getContentPane().add(canvas);
}
Also used : JmeCanvasContext(com.jme3.system.JmeCanvasContext) AppSettings(com.jme3.system.AppSettings) JFrame(javax.swing.JFrame) Canvas(java.awt.Canvas) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 37 with WindowAdapter

use of java.awt.event.WindowAdapter in project jmonkeyengine by jMonkeyEngine.

the class TestAwtPanels method createWindowForPanel.

private static void createWindowForPanel(AwtPanel panel, int location) {
    JFrame frame = new JFrame("Render Display " + location);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(panel, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            if (++panelsClosed == 2) {
                app.stop();
            }
        }
    });
    frame.pack();
    frame.setLocation(location, Toolkit.getDefaultToolkit().getScreenSize().height - 400);
    frame.setVisible(true);
}
Also used : BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 38 with WindowAdapter

use of java.awt.event.WindowAdapter in project lwjgl by LWJGL.

the class DemoBox method initialize.

/**
	 * @return
	 */
public boolean initialize() {
    setTitle("LWJGL - Demo Box");
    setSize(640, 480);
    setLayout(new GridBagLayout());
    // Setup selection panel
    // =================================
    selectionPanel = new Panel();
    selectionPanel.setLayout(new BorderLayout());
    selectionPanel.add(new Label("Demo", Label.CENTER), BorderLayout.NORTH);
    Button fullScreen = new Button("Fullscreen");
    fullScreen.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            toggleFullscreen();
        }
    });
    selectionPanel.add(fullScreen, BorderLayout.SOUTH);
    final List demos = new List();
    for (Enumeration e = selectableDemos.keys(); e.hasMoreElements(); ) {
        demos.add(e.nextElement().toString());
    }
    selectionPanel.add(demos, BorderLayout.CENTER);
    demos.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent event) {
            demoSelected(event.getItemSelectable().getSelectedObjects()[0].toString());
        }
    });
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    gbc.weightx = 0.05;
    gbc.weighty = 1.0;
    add(selectionPanel, gbc);
    // =================================
    try {
        demoCanvas = new DemoBoxGLCanvas(this);
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.weightx = 0.95;
        gbc.weighty = 1.0;
        add(demoCanvas, gbc);
    } catch (LWJGLException le) {
        le.printStackTrace();
        return false;
    }
    // ---------------------------------
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            demoCanvas.destroyCanvas();
            dispose();
            System.exit(0);
        }
    });
    //demoSelected(demos.getSelectedItem());
    return true;
}
Also used : ItemEvent(java.awt.event.ItemEvent) GridBagConstraints(java.awt.GridBagConstraints) Enumeration(java.util.Enumeration) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) Label(java.awt.Label) WindowAdapter(java.awt.event.WindowAdapter) Panel(java.awt.Panel) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) Button(java.awt.Button) WindowEvent(java.awt.event.WindowEvent) List(java.awt.List) ItemListener(java.awt.event.ItemListener) LWJGLException(org.lwjgl.LWJGLException)

Example 39 with WindowAdapter

use of java.awt.event.WindowAdapter in project intellij-community by JetBrains.

the class IdeFrameImpl method setupCloseAction.

private void setupCloseAction() {
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        public void windowClosing(@NotNull final WindowEvent e) {
            if (isTemporaryDisposed())
                return;
            final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
            if (openProjects.length > 1 || openProjects.length == 1 && SystemInfo.isMacSystemMenu) {
                if (myProject != null && myProject.isOpen()) {
                    ProjectUtil.closeAndDispose(myProject);
                }
                ApplicationManager.getApplication().getMessageBus().syncPublisher(AppLifecycleListener.TOPIC).projectFrameClosed();
                WelcomeFrame.showIfNoProjectOpened();
            } else {
                ApplicationManagerEx.getApplicationEx().exit();
            }
        }
    });
}
Also used : WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 40 with WindowAdapter

use of java.awt.event.WindowAdapter in project aima-java by aimacode.

the class MonteCarloLocalizationApp method constructBasicApplicationFrame.

/**
	 * Creates the {@code JFrame} for the application. A window listener is registered. 
	 * @return the main frame of the application.
	 */
public JFrame constructBasicApplicationFrame() {
    JFrame frame = app.constructApplicationFrame();
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            robotGui.saveSettings(settingsGui);
            if (settingsFile != null)
                settingsGui.saveSettings(settingsFile);
            robotGui.destructRobot();
        }
    });
    return frame;
}
Also used : JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Aggregations

WindowAdapter (java.awt.event.WindowAdapter)143 WindowEvent (java.awt.event.WindowEvent)140 JPanel (javax.swing.JPanel)40 JButton (javax.swing.JButton)36 JFrame (javax.swing.JFrame)34 BorderLayout (java.awt.BorderLayout)32 Dimension (java.awt.Dimension)30 JLabel (javax.swing.JLabel)26 JScrollPane (javax.swing.JScrollPane)25 ActionEvent (java.awt.event.ActionEvent)22 ActionListener (java.awt.event.ActionListener)20 FlowLayout (java.awt.FlowLayout)18 GridBagConstraints (java.awt.GridBagConstraints)18 GridBagLayout (java.awt.GridBagLayout)18 Insets (java.awt.Insets)14 Frame (java.awt.Frame)13 Container (java.awt.Container)12 JTextArea (javax.swing.JTextArea)12 JDialog (javax.swing.JDialog)11 IOException (java.io.IOException)9