List of usage examples for java.awt Frame addWindowListener
public synchronized void addWindowListener(WindowListener l)
From source file:ShapeMover.java
public static void main(String s[]) { Frame f = new Frame("ShapeMover"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);//w ww .jav a 2 s .c o m } }); Applet applet = new ShapeMover(); f.add("Center", applet); applet.init(); f.pack(); f.setSize(new Dimension(550, 250)); f.show(); }
From source file:TexturedText.java
/** "main program" method - construct and show */ public static void main(String[] av) { // create a TexturedText object, tell it to show up final Frame f = new Frame("TexturedText"); TexturedText comp = new TexturedText(); f.add(comp);//ww w. j av a 2s. c o m f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { f.setVisible(false); f.dispose(); System.exit(0); } }); f.pack(); f.setLocation(200, 200); f.setVisible(true); }
From source file:FileViewer.java
/** * The FileViewer can be used by other classes, or it can be used standalone * with this main() method./*from w w w.ja v a2 s.c om*/ */ static public void main(String[] args) throws IOException { // Create a FileViewer object Frame f = new FileViewer((args.length == 1) ? args[0] : null); // Arrange to exit when the FileViewer window closes f.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { System.exit(0); } }); // And pop the window up f.show(); }
From source file:Drag.java
/** * Used when running as an application. *//*w w w . j a v a 2 s .c om*/ public static void main(String[] args) { Drag drag = new Drag(); drag.setAppletFlag(false); drag.init(); Frame frame = new Frame("Drag the mouse in the window"); frame.setSize(640, 480); frame.add("Center", drag); frame.addWindowListener(new killAdapter()); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { Frame frame = new Frame("AppletAndApp as an Application"); myApplet = new MainClass(); frame.add(new Panel().add(myApplet)); frame.addNotify();/*from ww w . j a v a2 s.co m*/ myApplet.setStub(myStub = new MyStub(args)); myApplet.init(); frame.setSize(300, 200); frame.setVisible(true); myStub.setActive(true); myApplet.start(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent w) { myStub.setActive(false); myApplet.stop(); myApplet.destroy(); System.exit(0); } }); }
From source file:Main.java
public static void main() { Frame frame = new Frame(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { Frame frame = (Frame) evt.getSource(); frame.setVisible(false);/* w w w . j av a 2s . c om*/ // frame.dispose(); } }); }
From source file:ModalFrameUtil.java
public static void showAsModal(final Frame frame, final Frame owner) { frame.addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { owner.setEnabled(false);/*w w w . ja v a2 s.c o m*/ } public void windowClosing(WindowEvent e) { owner.setEnabled(true); frame.removeWindowListener(this); } public void windowClosed(WindowEvent e) { owner.setEnabled(true); frame.removeWindowListener(this); } }); owner.addWindowListener(new WindowAdapter() { public void windowActivated(WindowEvent e) { if (frame.isShowing()) { frame.setExtendedState(JFrame.NORMAL); frame.toFront(); } else { owner.removeWindowListener(this); } } }); frame.setVisible(true); try { new EventPump(frame).start(); } catch (Throwable throwable) { throw new RuntimeException(throwable); } }
From source file:Main.java
public static void main() { Frame frame = new Frame(); WindowListener listener = new WindowAdapter() { public void windowOpened(WindowEvent evt) { Frame frame = (Frame) evt.getSource(); System.out.println(frame.getTitle()); }/*from ww w . j av a 2 s . c om*/ public void windowClosing(WindowEvent evt) { Frame frame = (Frame) evt.getSource(); System.out.println(frame.getTitle()); } public void windowClosed(WindowEvent evt) { Frame frame = (Frame) evt.getSource(); System.out.println(frame.getTitle()); } }; frame.addWindowListener(listener); frame.setVisible(true); }
From source file:com.mirth.connect.plugins.rtfviewer.RTFViewer.java
@Override public void viewAttachments(List<String> attachmentIds) { // do viewing code Frame frame = new Frame("RTF Viewer"); frame.setLayout(new BorderLayout()); try {// ww w.j a v a2 s . com Attachment attachment = parent.mirthClient.getAttachment(attachmentIds.get(0)); byte[] rawRTF = Base64.decodeBase64(attachment.getData()); JEditorPane jEditorPane = new JEditorPane("text/rtf", new String(rawRTF)); if (jEditorPane.getDocument().getLength() == 0) { // decoded when it should not have been. i.e.) the attachment data was not encoded. jEditorPane.setText(new String(attachment.getData())); } jEditorPane.setEditable(false); JScrollPane scrollPane = new javax.swing.JScrollPane(); scrollPane.setViewportView(jEditorPane); frame.add(scrollPane); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } }); frame.setSize(600, 800); Dimension dlgSize = frame.getSize(); Dimension frmSize = parent.getSize(); Point loc = parent.getLocation(); if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) { frame.setLocationRelativeTo(null); } else { frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); } frame.setVisible(true); } catch (Exception e) { parent.alertException(parent, e.getStackTrace(), e.getMessage()); } }
From source file:com.mirth.connect.plugins.textviewer.TextViewer.java
@Override public void viewAttachments(String channelId, Long messageId, String attachmentId) { // do viewing code Frame frame = new Frame("Text Viewer"); frame.setLayout(new BorderLayout()); try {/*from ww w . jav a2 s . com*/ Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId); byte[] content = Base64.decodeBase64(attachment.getContent()); boolean isRTF = attachment.getType().toLowerCase().contains("rtf"); //TODO set character encoding JEditorPane jEditorPane = new JEditorPane(isRTF ? "text/rtf" : "text/plain", new String(content)); if (jEditorPane.getDocument().getLength() == 0) { // decoded when it should not have been. i.e.) the attachment data was not encoded. jEditorPane.setText(new String(attachment.getContent())); } jEditorPane.setEditable(false); JScrollPane scrollPane = new javax.swing.JScrollPane(); scrollPane.setViewportView(jEditorPane); frame.add(scrollPane); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } }); frame.setSize(600, 800); Dimension dlgSize = frame.getSize(); Dimension frmSize = parent.getSize(); Point loc = parent.getLocation(); if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) { frame.setLocationRelativeTo(null); } else { frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); } frame.setVisible(true); } catch (Exception e) { parent.alertThrowable(parent, e); } }