/** Simple test program. */ public static void main(String[] args) { final JFrame frame = new JFrame("Testing AddPersonDialog"); JButton button = new JButton("Click me"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { FamilyTree tree = new FamilyTree(); AddPersonDialog dialog = new AddPersonDialog(frame, tree); dialog.pack(); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); Person newPerson = dialog.getPerson(); if (newPerson != null) { tree.addPerson(newPerson); PrettyPrinter pretty = new PrettyPrinter(new PrintWriter(System.out, true)); pretty.dump(tree); } } }); frame.getContentPane().add(button); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(1); } }); frame.pack(); frame.setVisible(true); }
void makeFrame() { JPanel p = new JPanel(); p.setBackground(Color.blue); p.setLayout(new BorderLayout(0, 0)); p.setBorder(new EmptyBorder(0, GAP, GAP, GAP)); days.setFont(BIG); days.setForeground(COLOR); p.add(days, "North"); left.setFont(NORM); left.setForeground(COLOR); p.add(left, "South"); JFrame f = new JFrame("Sayaç"); // a window f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setContentPane(p); setDate(); f.pack(); // minimal size f.setVisible(true); // show f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { stop(); } }); }
public void go() throws IOException { // DefaultRouteTable route = new DefaultRouteTable(); // System.out.println(route.routeInfo()); // route.routeInfo(); totalSize = Toolkit.getDefaultToolkit().getScreenSize(); // getting screen size int width = totalSize.width; int height = totalSize.height; frame = new JFrame(); // creating frame frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { FileInput data = null; try { data = new FileInput("input.txt"); } catch (Exception e) { } String[][] origRoutes = convertArrayListTo2DArray(data.routeArrayList(data.routesToken), 1); String[][] routesList = Main.convertArrayListTo2DArray(routesInfo, 1); Main.changesCheck(origRoutes, routesList); } }); frame.setTitle("Air Route Planner"); frame.add(Panels()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize((width * 3 / 4), (height * 3 / 4)); frame.setJMenuBar(menuBar()); frame.setResizable(false); frame.setVisible(true); frame.setLocationRelativeTo(null); }
Main() { f = new JFrame("Wiki Seach"); JPanel p = new JPanel(); JPanel p1 = new JPanel(); b = new JButton("Search"); b1 = new JButton("Exit"); t = new JTextField(30); b.addActionListener(this); b1.addActionListener(this); p1.add(b); p1.add(b1); p.add(t); f.setLayout(new GridLayout(2, 1)); f.add(p); f.add(p1); f.pack(); f.setLocationRelativeTo(null); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.setVisible(true); }
/** * This method starts the GUI. * * @throws CoapException Thrown, if the connection to obix via CoAP fails. */ public void runGui() throws CoapException { this.lobby = obixChannel.getLobby(obixChannel.getLobbyUri()); // Create and set up the window. mainFrame = new JFrame("ObixConnector at " + obixChannel.getBaseUri() + ": " + obixChannel.getPort()); mainFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); mainFrame.setUndecorated(false); mainFrame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { close(); } }); Container contentPane = mainFrame.getContentPane(); // Create and set up the content pane. this.addComponentToPane(contentPane); // Display the window. mainFrame.pack(); executor.execute(updateThread); connector.addRunAndStopAble(updateThread); mainFrame.setVisible(true); }
private MainPanel(final JFrame frame) { super(); add(check); setPreferredSize(new Dimension(320, 240)); if (!SystemTray.isSupported()) { frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); return; } frame.addWindowListener( new WindowAdapter() { @Override public void windowIconified(WindowEvent e) { if (check.isSelected()) { e.getWindow().dispose(); } } }); // or // frame.addWindowStateListener(new WindowStateListener() { // @Override public void windowStateChanged(WindowEvent e) { // if (check.isSelected() && e.getNewState() == Frame.ICONIFIED) { // e.getWindow().dispose(); // } // } // }); final SystemTray tray = SystemTray.getSystemTray(); Dimension d = tray.getTrayIconSize(); BufferedImage image = makeBufferedImage(new StarIcon(), d.width, d.height); final PopupMenu popup = new PopupMenu(); final TrayIcon icon = new TrayIcon(image, "TRAY", popup); MenuItem item1 = new MenuItem("OPEN"); item1.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { frame.setVisible(true); } }); MenuItem item2 = new MenuItem("EXIT"); item2.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tray.remove(icon); frame.dispose(); // frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); } }); popup.add(item1); popup.add(item2); try { tray.add(icon); } catch (AWTException e) { e.printStackTrace(); } }
private void registerDisposeListeners() { dialog.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { disposeFrame(); } }); // handle window closing commands for ctrl/cmd-W or hitting ESC. Toolkit.registerWindowCloseKeys( dialog.getRootPane(), new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { disposeFrame(); } }); dialog .getContentPane() .addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { // System.out.println(e); KeyStroke wc = Toolkit.WINDOW_CLOSE_KEYSTROKE; if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) || (KeyStroke.getKeyStrokeForEvent(e).equals(wc))) { disposeFrame(); } } }); }
/** * Create the GUI and show it. For thread safety, this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("Automated File Mover"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { try { FileOutputStream f_out = new FileOutputStream(LOG_DIRECTORY + "save.data"); // Write object with ObjectOutputStream ObjectOutputStream obj_out = new ObjectOutputStream(f_out); // Write object out to disk obj_out.writeObject(directoryList); obj_out.writeObject(ERROR_LOG_NAME); obj_out.writeObject(MOVE_LOG_NAME); obj_out.flush(); obj_out.close(); printer.printError(LOG_DIRECTORY); } catch (IOException x) { printer.printError(x.toString()); } } }); // Create and set up the content pane. JComponent newContentPane = new fileBackupProgram(frame); newContentPane.setOpaque(true); // content panes must be opaque frame.setContentPane(newContentPane); // Display the window. frame.pack(); frame.setVisible(true); }
public static void main(String[] args) { JFrame frame = new JFrame("options"); frame.setSize(new Dimension(500, 300)); frame.getContentPane().add(new PackagerOptionsPanel(null)); frame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } @Override public void windowClosed(WindowEvent e) { System.exit(0); } }); try { SwingUtilities.invokeAndWait(new PackAndShowFrameWorker(frame)); } catch (InterruptedException e) { // Immediately reasserts the exception by interrupting the caller thread itself Thread.currentThread().interrupt(); e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } }
ChartGenerator createNewChart(final GUIState simulation) { generator = createNewGenerator(); globalAttributes = new GlobalAttributes(); generator.addGlobalAttribute(globalAttributes); // it'll be added last // set up the simulation -- need a new name other than guiObjects: and it should be // a HashMap rather than a Bag. if (simulation.guiObjects == null) simulation.guiObjects = new Bag(); simulation.guiObjects.add(generator); final JFrame f = generator.createFrame(simulation); WindowListener wl = new WindowListener() { public void windowActivated(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowClosing(WindowEvent e) { generator.quit(); } public void windowDeactivated(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowOpened(WindowEvent e) {} }; f.addWindowListener(wl); f.setVisible(true); return generator; }
public static void main(String args[]) { JFrame f = new JFrame("JPasswordField3"); Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout()); JPanel p1 = new JPanel(); // p1.setLayout(new GridLayout(4,2)); p1.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.WEST; // 设定Layout的位置 gbc.insets = new Insets(2, 2, 2, 2); // 设定与边界的距离(上,左,下,右) p1.setBorder(BorderFactory.createTitledBorder("您的基本数据")); JLabel l1 = new JLabel("姓名:"); JLabel l2 = new JLabel("性别:"); JLabel l3 = new JLabel("身高:"); JLabel l4 = new JLabel("体重:"); JPasswordField t1 = new JPasswordField(new JPasswordField3_OnlyNumberDocument(10), "", 10); JPasswordField t2 = new JPasswordField(new JPasswordField3_OnlyNumberDocument(1), "", 2); JPasswordField t3 = new JPasswordField(new JPasswordField3_OnlyNumberDocument(5), "", 5); JPasswordField t4 = new JPasswordField(new JPasswordField3_OnlyNumberDocument(5), "", 5); gbc.gridy = 1; gbc.gridx = 0; p1.add(l1, gbc); gbc.gridx = 1; p1.add(t1, gbc); gbc.gridy = 2; gbc.gridx = 0; p1.add(l2, gbc); gbc.gridx = 1; p1.add(t2, gbc); gbc.gridy = 3; gbc.gridx = 0; p1.add(l3, gbc); gbc.gridx = 1; p1.add(t3, gbc); gbc.gridy = 4; gbc.gridx = 0; p1.add(l4, gbc); gbc.gridx = 1; p1.add(t4, gbc); contentPane.add(p1); f.pack(); f.show(); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
/** EdiDialog constructor comment. */ public static void test() { JFrame frame = new JFrame(); frame.addWindowListener(new CloseSaveWindowsListener()); frame.setBackground(ConfigurableSystemSettings.backgroundColor.getAWTColor()); frame.getContentPane().setLayout(new java.awt.BorderLayout()); frame.setBounds(50, 50, 400, 400); frame.show(); DialogNewElement dialog = new DialogNewElement(frame); dialog.show(); }
public static void main(String[] args) { JFrame f = new JFrame("Model"); InitGraphics(f); // Exit application when the window is closed f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
private void mostrarGUI() { janela = new JFrame("Exemplo Swing - JFrame"); janela.setSize(400, 400); janela.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent windowEvent) { System.exit(0); } }); janela.setVisible(true); }
public LoginScreen(DBConnectionFactory factory) { this.factory = factory; loginFrame = new JFrame("Login"); loginFrame.setSize(500, 450); loginFrame.setVisible(true); Container content = loginFrame.getContentPane(); JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints cs = new GridBagConstraints(); cs.fill = GridBagConstraints.HORIZONTAL; lbUsername = new JLabel("Username: "******"Password: "******"Login"); loginButton.addActionListener(this); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); JPanel buttonPanel = new JPanel(); buttonPanel.add(loginButton); buttonPanel.add(cancelButton); content.add(panel, BorderLayout.CENTER); content.add(buttonPanel, BorderLayout.SOUTH); loginFrame.addWindowListener(new ExitListener()); }
// type 'java Parallel' to run this application public static void main(String args[]) throws VisADException, RemoteException, IOException { RealType index = RealType.getRealType("index"); RealType[] coords = new RealType[NCOORDS]; for (int i = 0; i < NCOORDS; i++) { coords[i] = RealType.getRealType("coord" + i); } RealTupleType range = new RealTupleType(coords); FunctionType ftype = new FunctionType(index, range); Integer1DSet index_set = new Integer1DSet(NROWS); float[][] samples = new float[NCOORDS][NROWS]; for (int i = 0; i < NCOORDS; i++) { for (int j = 0; j < NROWS; j++) { samples[i][j] = (float) Math.random(); } } FlatField data = new FlatField(ftype, index_set); data.setSamples(samples, false); // create a 2-D Display using Java3D DisplayImpl display = new DisplayImplJ3D("display", new TwoDDisplayRendererJ3D()); parallel(display, data); // create JFrame (i.e., a window) for display and slider JFrame frame = new JFrame("Parallel Coordinates VisAD Application"); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // create JPanel in JFrame JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.setAlignmentY(JPanel.TOP_ALIGNMENT); panel.setAlignmentX(JPanel.LEFT_ALIGNMENT); frame.getContentPane().add(panel); // add display to JPanel panel.add(display.getComponent()); // set size of JFrame and make it visible frame.setSize(500, 500); frame.setVisible(true); }
/** Create the entire GUI from scratch */ private void createGUI() { clientFrame = new JFrame("LeetFTP"); // Allow program to exit gracefully clientFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); createTabs(); createMenu(); // Top Options Bar connectButton = new JButton("Connect"); connectButton.addMouseListener(mouseHandler); optionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); optionPanel.add(connectButton); optionPanel.add(new JLabel("Name Server Hostname")); optionPanel.add(serverTextField); optionPanel.add(new JLabel("Port #")); optionPanel.add(portTextField); optionPanel.add(new JLabel("UserName")); optionPanel.add(nameTextField); // Bottom Transfer Table transferTable = new JTable(); transferPanel = new JPanel(new BorderLayout()); transferPanel.add(new JLabel("Current Transfers:"), BorderLayout.NORTH); transferPanel.add(transferTable); // Make the tab pane the GUI pane clientFrame.getContentPane().setLayout(new BorderLayout()); clientFrame.getContentPane().add(mainPanel); clientFrame.getContentPane().add(optionPanel, BorderLayout.NORTH); clientFrame.getContentPane().add(transferPanel, BorderLayout.SOUTH); // Set Client Window Properties clientFrame.setSize(800, 600); // clientFrame.setResizable(false); clientFrame.setLocationRelativeTo(null); clientFrame.setVisible(true); }
public static void main(String[] args) { BasicConfigurator.configure(); initializeLookAndFeels(); final JFrame frame = new JpasFrame(); frame.addWindowListener( new WindowAdapter() { public void windowClosing(final WindowEvent we) { System.exit(0); } }); frame.setVisible(true); }
public static void main(String[] args) { JFrame ventana = new JFrame("Open"); ventana.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); ventana.getContentPane().add(new marcador(), BorderLayout.CENTER); ventana.setSize(300, 100); ventana.setVisible(true); }
public static void main(String[] args) { TestTtsp ttsp = new TestTtsp(); JFrame jframe = new JFrame("TTSP - Time Precision Error"); ttsp.setPrecisionErrorChart(new PrecisionErrorChart()); jframe.getContentPane().add(ttsp.getPrecisionErrorChart(), "Center"); jframe.setBounds(200, 120, 600, 280); jframe.setVisible(true); jframe.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent windowevent) { System.exit(0); } }); JFrame jframe2 = new JFrame("TTSP - Synchronization Period"); ttsp.setSyncPeriodChart(new SyncPeriodChart()); jframe2.getContentPane().add(ttsp.getSyncPeriodChart(), "Center"); jframe2.setBounds(200, 120, 600, 280); jframe2.setVisible(true); jframe2.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent windowevent) { System.exit(0); } }); try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block // e.printStackTrace(); } }
/** Creates the JFrame that will contain everything. */ protected JFrame createFrame() { JFrame retFrame = new JFrame("TreeTable III -- " + path); Dimension dimension = new Dimension(600, 400); retFrame.setSize(600, 600); retFrame.setMinimumSize(dimension); retFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { frame.dispose(); if (--ttCount == 0) { System.exit(0); } } }); return retFrame; }
public static void main(String arg[]) { JFrame f = new JFrame("SimpleBorder"); Container content = f.getContentPane(); JButton b = new JButton(); b.setBorder(BorderFactory.createLineBorder(Color.blue, 10)); content.add(b); f.setSize(200, 150); f.show(); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("DragLabel test"); Container cont = frame.getContentPane(); DragLabel l = new DragLabel("Here is some text"); l.setBackground(Color.black); l.setForeground(Color.yellow); cont.add(l); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.setSize(300, 300); frame.setVisible(true); }
public static void main(String[] args) { // Create the top-level container and add contents to it. JFrame frame = new JFrame("Inner Class Demo 2"); final InnerClassDemo2 app = new InnerClassDemo2(); Component contents = app.createComponents(); frame.getContentPane().add(contents, BorderLayout.CENTER); // Finish setting up the frame, and show it. frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { app.quit(); } }); frame.pack(); frame.setVisible(true); }
private void mostrarGUI() { janela = new JFrame("Java Swing Examples"); janela.setSize(400, 400); janela.setLayout(new GridLayout(3, 1)); janela.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent windowEvent) { System.exit(0); } }); statusLabel = new JLabel("", JLabel.CENTER); statusLabel.setSize(350, 100); controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout()); ImageIcon icon = criarImageIcon("/resources/home153.png", "Home"); JButton okButton = new JButton("OK"); // JButton homeButton = new JButton("Home", icon); okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { statusLabel.setText("Clicou no Botao Ok."); } }); /* homeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { statusLabel.setText("Clicou no Botao Home."); } }); */ controlPanel.add(okButton); // controlPanel.add(homeButton); janela.add(statusLabel); janela.add(controlPanel); janela.setVisible(true); }
/** * Main method for testing * * @param args arguments */ public static void main(String[] args) { JFrame frame = new JFrame(); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); AnimationWidget widget = new AnimationWidget(frame); frame.getContentPane().add(widget.getContents()); frame.pack(); frame.setVisible(true); }
public static void main(String[] args) { JFrame f = new JFrame("Password test"); f.setSize(300, 100); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.setVisible(true); while (true) { pmLogin d = new pmLogin(f, "Test Login", "NIS/LDAP Authentication."); d.setVisible(true); } // System.exit(0); }
public static void main(String s[]) { if (s.length > 0) j2kfilename = s[0]; else j2kfilename = "girl"; System.out.println(j2kfilename); isApplet = false; JFrame f = new JFrame("ImageViewer"); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); JApplet applet = new ImageViewer(); f.getContentPane().add("Center", applet); applet.init(); f.pack(); f.setSize(new Dimension(550, 550)); f.show(); }
public static void main(String s[]) { JFrame frame = new JFrame("Exportator"); AppExport panel = new AppExport(); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); Image im = Toolkit.getDefaultToolkit().getImage("images/ExportIco.jpg"); frame.setIconImage(im); frame.getContentPane().add(panel, "Center"); frame.setSize(panel.getPreferredSize()); frame.setVisible(true); frame.setResizable(false); frame.setLocationRelativeTo(null); }
public SharedActions(final JFrame frame) { this.frame = frame; buildActionTable(); buildPopupMenu(); JTextPane textPane = new JTextPane(); textPane.setEditable(false); textPane.setText( "\n\tUse the MenuBar, ToolBar or right-click for a popup menu.\n\n" + "\tAction1 disables itself and enables Action2.\n" + "\tAction2 disables itself and enables Action1.\n" + "\tAction3 and Action4 support toggle buttons and checkboxes.\n" + "\tThe About action enables Actions 1 and 2 and selects Actions 3 and 4.\n\n" + "\tAll components use a common set of actions.\n" + "\tThe actions and corresponding components\n" + "\tare enabled and disabled in concert.\n\n" + "\tFor larger swing applications, I place all actions\n" + "\tin a separate package which maps to a directory structure\n" + "\tsomething like this...\n\n" + "\tmypackage \n" + "\t\tSharedActions.java\n" + "\tmypackage/action\n" + "\t\tExitAction.java\n" + "\t\tAction1.java\n" + "\t\tAction2.java\n" + "\t\tAboutAction.java\n"); frame.getContentPane().add(new MyToolBar(actionTable), BorderLayout.NORTH); frame.getContentPane().add(new JScrollPane(textPane), BorderLayout.CENTER); textPane.addMouseListener(new MousePopupListener()); frame.setJMenuBar(new MyMenuBar(actionTable)); frame.setSize(640, 480); // send window closing events to our "Exit" action handler. frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { getAction(SharedActions.EXIT_KEY).actionPerformed(null); } }); }