List of usage examples for java.awt.event WindowAdapter WindowAdapter
WindowAdapter
From source file:emperior.Main.java
public static void main(String[] args) throws Exception { mainFrame = new MainFrame(); operatingSystem = System.getProperty("os.name"); CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "help", false, "Print this usage information"); options.addOption("t", "test", true, "Name of the Bat-File which is executed for Compilation and Unit-Testing"); options.addOption("r", "run", true, "Name of the Bat-File which is executed for Compilation and running the project"); options.addOption("f", "folder", true, "Name of the Folder in which the exercises for the Experiment are stored"); CommandLine commandLine = parser.parse(options, args); // read from command line if (commandLine.getOptions().length > 0) { readCommandLine(commandLine, options); }//from www . j a v a 2 s .c o m // read from property file else { readPropertyFile(); } initLogging(); checkBatFile(); addLineToLogFile("[Start] Emperior"); if (resuming) Main.addLineToLogFile("[ResumeTask] Resume task: " + Main.tasktypes.get(Main.activeType) + "_" + Main.tasks.get(Main.activeTask)); else { Main.addLineToLogFile("[StartTask] Start new task: " + Main.tasktypes.get(Main.activeType) + "_" + Main.tasks.get(Main.activeTask)); startedWith = Main.tasktypes.get(Main.activeType) + "_" + Main.tasks.get(Main.activeTask); updateStartedWithTask(Main.tasktypes.get(Main.activeType) + "_" + Main.tasks.get(Main.activeTask)); } mainFrame.init(); mainFrame.setSize(800, 600); mainFrame.setVisible(true); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { Main.addLineToLogFile("[PauseTask] Stop task: " + Main.tasktypes.get(Main.activeType) + "_" + Main.tasks.get(Main.activeTask)); addLineToLogFile("[Close] Emperior"); updateResumeTask(tasktypes.get(activeType) + "_" + tasks.get(activeTask)); System.exit(0); } }); mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); //makeContiniousCopys(); }
From source file:fll.scheduler.SchedulerUI.java
public static void main(final String[] args) { LogUtils.initializeLogging();//from w w w . j av a2s.com Thread.setDefaultUncaughtExceptionHandler(new GuiExceptionHandler()); // Use cross platform look and feel so that things look right all of the // time try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (final ClassNotFoundException e) { LOGGER.warn("Could not find cross platform look and feel class", e); } catch (final InstantiationException e) { LOGGER.warn("Could not instantiate cross platform look and feel class", e); } catch (final IllegalAccessException e) { LOGGER.warn("Error loading cross platform look and feel", e); } catch (final UnsupportedLookAndFeelException e) { LOGGER.warn("Cross platform look and feel unsupported?", e); } try { final SchedulerUI frame = new SchedulerUI(); frame.addWindowListener(new WindowAdapter() { @Override @SuppressFBWarnings(value = { "DM_EXIT" }, justification = "Exiting from main is OK") public void windowClosing(final WindowEvent e) { System.exit(0); } @Override @SuppressFBWarnings(value = { "DM_EXIT" }, justification = "Exiting from main is OK") public void windowClosed(final WindowEvent e) { System.exit(0); } }); // should be able to watch for window closing, but hidden works frame.addComponentListener(new ComponentAdapter() { @Override @SuppressFBWarnings(value = { "DM_EXIT" }, justification = "Exiting from main is OK") public void componentHidden(final ComponentEvent e) { System.exit(0); } }); GraphicsUtils.centerWindow(frame); frame.setVisible(true); } catch (final Exception e) { LOGGER.fatal("Unexpected error", e); JOptionPane.showMessageDialog(null, "An unexpected error occurred. Please send the log file and a description of what you were doing to the developer. Error message: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:QueueMonitor.java
/** Main program entry point. */ public static void main(String[] args) { // There should be no arguments to this program. if (args.length > 0) { printUsage();/*from w w w . j a va 2s . c o m*/ System.exit(1); } QueueMonitor queueMonitor = new QueueMonitor(); queueMonitor.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); screenSize.height = screenSize.height / 2; screenSize.width = screenSize.width / 2; queueMonitor.setSize(screenSize); queueMonitor.setVisible(true); }
From source file:net.sf.jhylafax.addressbook.AddressBook.java
/** * @param args//w w w . j a v a 2 s . c o m */ public static void main(String[] args) { final AddressBook app = new AddressBook(); app.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); app.restoreLayout(new SettingStore(Settings.backstore)); try { File file = JHylaFAX.getAddressBookFile(); if (file.exists()) { app.load(file); } } catch (Exception e) { ErrorDialog.showError(null, i18n.tr("Could not load address book"), i18n.tr("JHylaFAX Error"), e); } app.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { try { File file = JHylaFAX.getAddressBookFile(); app.store(file); } catch (Exception e) { ErrorDialog.showError(null, i18n.tr("Could not store address book"), i18n.tr("JHylaFAX Error"), e); } } }); app.setVisible(true); }
From source file:UndoExample5.java
public static void main(String[] args) { try {//from w w w. j a v a 2s.c om UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new UndoExample5(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(250, 300); f.setVisible(true); // Create and show a frame monitoring undoable edits JFrame undoMonitor = new JFrame("Undo Monitor"); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); undoMonitor.getContentPane().add(new JScrollPane(textArea)); undoMonitor.setBounds(f.getLocation().x + f.getSize().width, f.getLocation().y, 400, 200); undoMonitor.setVisible(true); pane.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { UndoableEdit edit = evt.getEdit(); textArea.append(edit.getPresentationName() + "(" + edit.toString() + ")\n"); } }); // Create and show a frame monitoring document edits JFrame editMonitor = new JFrame("Edit Monitor"); final JTextArea textArea2 = new JTextArea(); textArea2.setEditable(false); editMonitor.getContentPane().add(new JScrollPane(textArea2)); editMonitor.setBounds(undoMonitor.getLocation().x, undoMonitor.getLocation().y + undoMonitor.getSize().height, 400, 200); editMonitor.setVisible(true); pane.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent evt) { textArea2.append("Attribute change\n"); } public void insertUpdate(DocumentEvent evt) { textArea2.append("Text insertion\n"); } public void removeUpdate(DocumentEvent evt) { textArea2.append("Text removal\n"); } }); }
From source file:de.codesourcery.geoip.Main.java
public static void main(String[] args) throws Exception { final IGeoLocator<StringSubject> locator = createGeoLocator(); final JFrame frame = new JFrame("GeoIP"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { try { locator.dispose();/* w w w.jav a2s .c o m*/ } catch (Exception e1) { e1.printStackTrace(); } }; }); final MapImage image = MapImage.getRobinsonWorldMap(); // MapImage.getMillerWorldMap(); final MapCanvas canvas = new MapCanvas(image); for (GeoLocation<StringSubject> loc : locator.locate(getSpammers())) { if (loc.hasValidCoordinates()) { canvas.addCoordinate(PointRenderer.createPoint(loc, Color.YELLOW)); } } // canvas.addCoordinate( PointRenderer.createPoint( ZERO , Color.YELLOW ) ); // canvas.addCoordinate( PointRenderer.createPoint( WELLINGTON , Color.RED ) ); // canvas.addCoordinate( PointRenderer.createPoint( MELBOURNE , Color.RED ) ); // canvas.addCoordinate( PointRenderer.createPoint( HAMBURG , Color.RED ) ); final double heightToWidth = image.height() / (double) image.width(); // preserve aspect ratio of map canvas.setPreferredSize(new Dimension(640, (int) Math.round(640 * heightToWidth))); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); panel.add(new JLabel("Scale-X")); final JTextField scaleX = new JTextField(Double.toString(image.getScaleX())); scaleX.setColumns(5); final JTextField scaleY = new JTextField(Double.toString(image.getScaleY())); scaleY.setColumns(5); final ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double x = Double.parseDouble(scaleX.getText()); double y = Double.parseDouble(scaleY.getText()); image.setScale(x, y); canvas.repaint(); } }; scaleX.addActionListener(listener); scaleY.addActionListener(listener); panel.add(new JLabel("Scale-X")); panel.add(scaleX); panel.add(new JLabel("Scale-Y")); panel.add(scaleY); final JTextField ipAddress = new JTextField("www.kickstarter.com"); ipAddress.setColumns(20); final ActionListener ipListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final String destinationIP = ipAddress.getText(); if (StringUtils.isBlank(destinationIP)) { return; } /* * Perform traceroute. */ final List<String> hops; try { if (TracePath.isPathTracingAvailable()) { hops = TracePath.trace(destinationIP); } else { System.err.println("tracepath not available."); if (TracePath.isValidAddress(destinationIP)) { hops = new ArrayList<>(); hops.add(destinationIP); } else { System.err.println(destinationIP + " is no valid IP"); return; } } } catch (Exception ex) { System.err.println("Failed to trace " + destinationIP); ex.printStackTrace(); return; } System.out.println("Trace contains " + hops.size() + " IPs"); /* * Gather locations. */ final List<StringSubject> subjects = new ArrayList<>(); for (String ip : hops) { subjects.add(new StringSubject(ip)); } final List<GeoLocation<StringSubject>> locations; try { long time = -System.currentTimeMillis(); locations = locator.locate(subjects); time += System.currentTimeMillis(); System.out.println("Locating hops for " + destinationIP + " returned " + locations.size() + " valid locations ( time: " + time + " ms)"); System.out.flush(); } catch (Exception e2) { e2.printStackTrace(); return; } /* * Weed-out invalid/unknown locations. */ { GeoLocation<StringSubject> previous = null; for (Iterator<GeoLocation<StringSubject>> it = locations.iterator(); it.hasNext();) { final GeoLocation<StringSubject> location = it.next(); if (!location.hasValidCoordinates() || (previous != null && previous.coordinate().equals(location.coordinate()))) { it.remove(); System.err.println("Ignoring invalid/duplicate location for " + location); } else { previous = location; } } } /* * Populate chart. */ System.out.println("Adding " + locations.size() + " hops to chart"); System.out.flush(); canvas.removeAllCoordinates(); if (locations.size() == 1) { canvas.addCoordinate( PointRenderer.createPoint(locations.get(0), getLabel(locations.get(0)), Color.BLACK)); } else if (locations.size() > 1) { GeoLocation<StringSubject> previous = locations.get(0); MapPoint previousPoint = PointRenderer.createPoint(previous, getLabel(previous), Color.BLACK); final int len = locations.size(); for (int i = 1; i < len; i++) { final GeoLocation<StringSubject> current = locations.get(i); // final MapPoint currentPoint = PointRenderer.createPoint( current , getLabel( current ) , Color.BLACK ); final MapPoint currentPoint = PointRenderer.createPoint(current, Color.BLACK); // canvas.addCoordinate( LineRenderer.createLine( previousPoint , currentPoint , Color.RED ) ); canvas.addCoordinate(CurvedLineRenderer.createLine(previousPoint, currentPoint, Color.RED)); previous = locations.get(i); previousPoint = currentPoint; } } System.out.println("Finished adding"); System.out.flush(); canvas.repaint(); } }; ipAddress.addActionListener(ipListener); panel.add(new JLabel("IP")); panel.add(ipAddress); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(panel, BorderLayout.NORTH); frame.getContentPane().add(canvas, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:EditorDropTarget.java
public static void main(String[] args) { try {//from ww w . j a va 2s . c om UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } final JFrame f = new JFrame("JEditor Pane Drop Target Example 1"); JEditorPane pane = new JEditorPane(); // Add a drop target to the JEditorPane EditorDropTarget target = new EditorDropTarget(pane); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER); f.setSize(500, 400); f.setVisible(true); }
From source file:Composite.java
public static void main(String s[]) { JFrame f = new JFrame("Composite"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/*from w ww. j a v a 2s . c om*/ } }); JApplet applet = new Composite(); f.getContentPane().add("Center", applet); applet.init(); f.pack(); f.setSize(new Dimension(300, 300)); f.setVisible(true); }
From source file:PanelDropTarget.java
public static void main(String[] args) { try {//from w w w . jav a2 s . c o m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } final JFrame f = new JFrame("Component drop target example"); JPanel pane = new JPanel(); // Add a drop target to the JPanel PanelDropTarget target = new PanelDropTarget(pane); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER); f.setSize(500, 400); f.setVisible(true); }
From source file:ImageOps.java
public static void main(String s[]) { JFrame f = new JFrame("ImageOps"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);//from w w w . j a v a 2 s . co m } }); JApplet applet = new ImageOps(); f.getContentPane().add("Center", applet); applet.init(); f.pack(); f.setSize(new Dimension(550, 550)); f.show(); }