Example usage for java.awt Frame addWindowListener

List of usage examples for java.awt Frame addWindowListener

Introduction

In this page you can find the example usage for java.awt Frame addWindowListener.

Prototype

public synchronized void addWindowListener(WindowListener l) 

Source Link

Document

Adds the specified window listener to receive window events from this window.

Usage

From source file:com.jcraft.weirdx.XWindow.java

private void addWindowListener(java.awt.Frame foo) {
    final java.awt.Frame frame = foo;
    frame.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosed(java.awt.event.WindowEvent e) {
        }/*from  www  .ja  v  a2s  . c  o m*/

        public void windowClosing(java.awt.event.WindowEvent e) {
            int message_type = XAtom.find("WM_PROTOCOLS");
            int del = XAtom.find("WM_DELETE_WINDOW");

            synchronized (XWindow.LOCK) {
                Property p = getProperty();
                while (p != null) {
                    if (p.propertyName == message_type)
                        break;
                    p = p.next;
                }

                if (p != null && p.data != null) {
                } else {
                    try {
                        getClient().closeDown();
                    } catch (Exception ee) {
                    }
                    return;
                }
            }

            if (message_type == 0 || del == 0)
                return;

            Event event = new Event();
            event.mkClientMessage(id, message_type);
            byte[] eb = event.event;
            eb[1] = 32;

            eb[12] = (byte) (del >>> 24); //protocol
            eb[13] = (byte) (del >>> 16);
            eb[14] = (byte) (del >>> 8);
            eb[15] = (byte) (del);

            int tm = (int) System.currentTimeMillis();
            eb[16] = (byte) (tm >>> 24); //time
            eb[17] = (byte) (tm >>> 16);
            eb[18] = (byte) (tm >>> 8);
            eb[19] = (byte) (tm);

            eb[20] = eb[21] = eb[22] = eb[23] = 0;
            eb[24] = eb[25] = eb[26] = eb[27] = 0;
            eb[28] = eb[29] = eb[30] = eb[31] = 0;

            eb[0] |= 0x80;

            try {
                sendEvent(event, 1, Event.NoEventMask, null, 0);
            } catch (Exception ee) {
            }
        }
    });
}

From source file:org.geoserver.wms.WMSTestSupport.java

/**
 * Shows <code>image</code> in a Frame.
 * /*  w  ww .j  a  va  2s. c om*/
 * @param frameName
 * @param timeOut
 * @param image
 */
public static void showImage(String frameName, long timeOut, final BufferedImage image) {
    int width = image.getWidth();
    int height = image.getHeight();

    if (((System.getProperty("java.awt.headless") == null)
            || !System.getProperty("java.awt.headless").equals("true")) && INTERACTIVE) {
        Frame frame = new Frame(frameName);
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        Panel p = new Panel(null) { // no layout manager so it respects
                                    // setSize
            public void paint(Graphics g) {
                g.drawImage(image, 0, 0, this);
            }
        };

        frame.add(p);
        p.setSize(width, height);
        frame.pack();
        frame.setVisible(true);

        try {
            Thread.sleep(timeOut);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        frame.dispose();
    }
}

From source file:org.opensc.test.pkcs11.PINEntry.java

/**
 * Contructs a PINEntry instance. /*w  ww  .ja  v a2s  . com*/
 */
public PINEntry() {
    super();
    Frame frame = new Frame("PIN entry");

    frame.setLayout(new GridLayout(2, 2));

    frame.add(new Label("Event:"));

    this.label = new Label("NO_EVENT");
    frame.add(this.label);

    this.prompt = new Label();
    frame.add(this.prompt);

    this.listener = new PINListener(frame);

    this.textField = new TextField();
    this.textField.setEchoChar('*');
    this.textField.addKeyListener(this.listener);
    frame.add(this.textField);
    frame.addWindowListener(this.listener);

    frame.pack();
    frame.setVisible(true);

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    Rectangle r = gc.getBounds();
    Point p = new Point((r.width - frame.getWidth()) / 2, (r.height - frame.getHeight()) / 2);

    frame.setLocation(p);
}

From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java

public static Frame getNonClearingFrame(String name, Component c) {
    final Frame f = new Frame(name) {

        @Override/*  w w w . j ava 2  s. co  m*/
        public void update(Graphics g) {
            paint(g);
        }
    };
    sizeContainerToComponent(f, c);
    centerFrame(f);
    f.setLayout(new BorderLayout());
    f.add(c, BorderLayout.CENTER);
    f.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            f.dispose();
        }
    });
    return f;
}