// --------------------------------actionConnect------------------------------ private void actionConnect() { if (oParty == null) { JOptionPane.showMessageDialog(frame, "Make a party before trying to connect."); return; } String[] oResults = (String[]) DialogManager.show(DialogManager.CONNECT, frame); if (oResults[DialogManager.RETURN_IP].equals("cancel")) return; lblStatus3.setText("Connecting..."); try { oConn.connect( oResults[DialogManager.RETURN_IP], Integer.parseInt(oResults[DialogManager.RETURN_PORT])); } catch (UnknownHostException e) { JOptionPane.showMessageDialog( frame, "The IP of the host cannot be determined.", "Unknown Host Exception", JOptionPane.ERROR_MESSAGE); frame.repaint(); return; } catch (IOException e) { JOptionPane.showMessageDialog( frame, e.getMessage(), "Input/Output Exception", JOptionPane.ERROR_MESSAGE); frame.repaint(); return; } echo("Connected to opponent!"); tConn = new Thread(oConn, "conn"); tConn.start(); tMain = new Thread(this, "main"); tMain.start(); }
public int getTitleHeight(Component c) { int th = 21; int fh = getBorderInsets(c).top + getBorderInsets(c).bottom; if (c instanceof JDialog) { JDialog dialog = (JDialog) c; th = dialog.getSize().height - dialog.getContentPane().getSize().height - fh - 1; if (dialog.getJMenuBar() != null) { th -= dialog.getJMenuBar().getSize().height; } } else if (c instanceof JInternalFrame) { JInternalFrame frame = (JInternalFrame) c; th = frame.getSize().height - frame.getRootPane().getSize().height - fh - 1; if (frame.getJMenuBar() != null) { th -= frame.getJMenuBar().getSize().height; } } else if (c instanceof JRootPane) { JRootPane jp = (JRootPane) c; if (jp.getParent() instanceof JFrame) { JFrame frame = (JFrame) c.getParent(); th = frame.getSize().height - frame.getContentPane().getSize().height - fh - 1; if (frame.getJMenuBar() != null) { th -= frame.getJMenuBar().getSize().height; } } else if (jp.getParent() instanceof JDialog) { JDialog dialog = (JDialog) c.getParent(); th = dialog.getSize().height - dialog.getContentPane().getSize().height - fh - 1; if (dialog.getJMenuBar() != null) { th -= dialog.getJMenuBar().getSize().height; } } } return th; }
public static void main(String[] arg) { // init table with Random Random alea = new Random(System.currentTimeMillis()); for (int i = 0; i < table.length; i++) { table[i] = alea.nextInt(10); } System.out.println(Arrays.toString(table)); // pick median values 3 by 3 using Arrays.sort for (int i = 1; (i < table.length - 1); i++) { int[] sort3 = {table[i - 1], table[i], table[i + 1]}; Arrays.sort(sort3); median[i] = sort3[1]; System.out.printf("%d %d %d : %d\n", table[i - 1], table[i], table[i + 1], median[i]); } System.out.println(Arrays.toString(median)); // create Frame + Panel + Graphics JFrame cadre = new JFrame(); JPanel ardoise = new Graph(); cadre.setVisible(true); cadre.setContentPane(ardoise); cadre.pack(); cadre.setLocation(100, 100); }
/** * Constructs a new game. * * @param web <code>true</code> if this game is meant to be an applet (which can be played * online), and <code>false</code> otherwise. Note: this doesn't work yet. */ public Game() { Game.applet = false; canvas = new Canvas(this); solidShapes = Collections.newSetFromMap(new ConcurrentHashMap<Shape, Boolean>()); allShapes = Collections.newSetFromMap(new ConcurrentHashMap<Shape, Boolean>()); // TODO: sort out which data structures actually have to support concurrency layerContents = new ConcurrentHashMap<Integer, java.util.List<Shape>>(); layers = new CopyOnWriteArrayList<Integer>(); layerOf = new ConcurrentHashMap<Shape, Integer>(); counters = new ArrayList<Counter>(); Mouse mouse = new Mouse(); if (applet) { addMouseMotionListener(mouse); addMouseListener(mouse); addKeyListener(new Keyboard()); } else { frame = new JFrame(); frame.addMouseMotionListener(mouse); frame.addMouseListener(mouse); frame.addKeyListener(new Keyboard()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } setDefaults(); }
public static void main(String[] args) { Example4 ef = new Example4(); try { final String molS = "C1C2=CC=CC=C2C3=C4CC5=CC=CC=C5C4=C6CC7=CC=CC=C7C6=C13"; Molecule mol = MolImporter.importMol(molS); PolarizabilityPlugin plugin = new PolarizabilityPlugin(); plugin.setMolecule(mol); plugin.run(); ArrayList values = new ArrayList(); java.text.NumberFormat nf = java.text.NumberFormat.getInstance(); nf.setMaximumFractionDigits(3); for (int i = 0; i < mol.getAtomCount(); i++) { values.add(Float.valueOf(nf.format(((Double) plugin.getResult(i)).floatValue()))); } mol.hydrogenize(true); for (int i = 0; i < mol.getExplicitHcount(); i++) { values.add(new Double(0)); } ef.setPlugin(plugin); JFrame frame = ef.createSpaceFrame(mol, values); frame.setTitle("Polarizability"); java.net.URL u = ef.getClass().getResource("/chemaxon/marvin/space/gui/mspace16.gif"); frame.setIconImage( Toolkit.getDefaultToolkit().createImage((java.awt.image.ImageProducer) u.getContent())); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } }
public void launchTrajectoryRenderer() { Visualizer tv = this.getTrajectoryRenderLayerBase(); List<EpisodeAnalysis> trajectories = EpisodeAnalysis.parseFilesIntoEAList(this.expertDir, this.domain, this.sp); TrajectoryRenderer tr = new TrajectoryRenderer( trajectories, GridWorldDomain.CLASSAGENT, GridWorldDomain.ATTX, GridWorldDomain.ATTY, new double[] {0, 30, .5}, new double[] {0, 30, .5}, 3.f, 10.f); tv.addRenderLayer(tr); tv.updateState(trajectories.get(0).getState(0)); JFrame frame = new JFrame(); frame.setPreferredSize(new Dimension(800, 800)); frame.getContentPane().add(tv); frame.pack(); frame.setVisible(true); }
public static void main(String[] args) { JFrame win = new JFrame("MouseMotionEvents"); win.setSize(1024, 768); win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); win.add(new MouseMotionEvents()); win.setVisible(true); }
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 void actionPerformed(ActionEvent ae) { if (ae.getSource() == b1) { try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "123"); PreparedStatement ps = con.prepareStatement("select * from LoginForm where username=? and password=?"); String UserName = t1.getText(); String Password = jp1.getText(); ps.setString(1, UserName); ps.setString(2, Password); ResultSet rs = ps.executeQuery(); boolean flag = rs.next(); if (flag) { new Main(); f.setVisible(false); } else { JOptionPane.showMessageDialog(null, "Please Enter valid Name And Password"); } } catch (Exception e) { System.out.println("Error:" + e); } } else if (ae.getSource() == b2) { t1.setText(""); jp1.setText(""); } else if (ae.getSource() == b3) { f.setVisible(false); } }
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(); } }
public static void main(String[] args) { StringBuffer result = new StringBuffer("<html><body><h1>Fibonacci Sequence</h1><ol>"); long f1 = 0; long f2 = 1; for (int i = 0; i < 50; i++) { result.append("<li>"); result.append(f1); long temp = f2; f2 = f1 + f2; f1 = temp; } result.append("</ol></body></html>"); JEditorPane jep = new JEditorPane("text/html", result.toString()); jep.setEditable(false); // new FibonocciRectangles().execute(); JScrollPane scrollPane = new JScrollPane(jep); JFrame f = new JFrame("Fibonacci Sequence"); f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); f.setContentPane(scrollPane); f.setSize(512, 342); EventQueue.invokeLater(new FrameShower(f)); }
public void openCaptureWindow() { if (framenr - lastcapture_framenr < number_of_frames_before_cwopen) { return; } // Capture Window cw.setVisible(true); cw.toFront(); // Timer for closing the capturewindow TimerTask task = new TimerTask() { @Override public void run() { EventQueue.invokeLater( new Runnable() { public void run() { System.out.println("Closing cw..."); cw.setVisible(false); cwText.setText(""); // Empty text in case there is a text } }); } }; cwTimer = new Timer(); cwTimer.schedule(task, number_of_second_capturewindow * 1000); }
public void minimiseAllWindows() { for (int i = 0; i < controllers.size(); i++) { SwingController controller = controllers.get(i); JFrame frame = controller.getViewerFrame(); if (frame != null) frame.setState(Frame.ICONIFIED); } }
public static void main(String[] args) { JFrame frame = new JFrame(); frame.add(new JDemoFontMetrics()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 460); frame.setVisible(true); }
private static void badFetch() { final JFrame frame = new JFrame("TestFetchWebGui"); final JPanel outerPanel = new JPanel(), buttonPanel = new JPanel(); final JButton fetchButton = new JButton("Fetch"), cancelButton = new JButton("Cancel"); frame.add(outerPanel); outerPanel.setLayout(new BorderLayout()); buttonPanel.setLayout(new GridLayout(2, 1)); buttonPanel.add(fetchButton); buttonPanel.add(cancelButton); outerPanel.add(buttonPanel, BorderLayout.EAST); final TextArea textArea = new TextArea(25, 80); textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); outerPanel.add(textArea, BorderLayout.WEST); fetchButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { for (String url : urls) { System.out.println("Fetching " + url); String page = getPage(url, 200); textArea.append(String.format("%-40s%7d%n", url, page.length())); } } }); frame.pack(); frame.setVisible(true); }
public Processing(Box root) { super(null); Log.log("startup.processing", " processing plugin is starting up "); frame = new JFrame("Field/Processing"); __applet = new FieldProcessingApplet( sizeX, sizeY, queue, this, s -> { if (getLastErrorOutput() != null) getLastErrorOutput().accept(new Pair<>(-1, s)); }); __applet.init(); __applet.loop(); frame.add(__applet, BorderLayout.CENTER); frame.setSize(sizeX, sizeY); frame.setVisible(true); frame.validate(); applet = new FieldProcessingAppletDelgate(__applet); this.properties.put(P, applet); Log.log("startup.processing", " searching for boxes that need processing support "); Log.log("startup.processing", " processing plugin has finished starting up "); }
public void actionPerformed(ActionEvent e) { if (e.getSource() == creer) { this.setVisible(false); JFrame fenetremilieu = new FenetreMilieu(this); fenetremilieu.setVisible(true); fenetremilieu.setLocation(500, 500); } if (e.getSource() == quitter) { this.dispose(); } if (e.getSource() == options) { String message = "Choisissez le port"; numport = Integer.parseInt(JOptionPane.showInputDialog(this, message)); // JFrame fenetreoptions = new FenetreOptions(); // fenetreoptions.setVisible(true); } }
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(); } } }); }
/** * Load a file of a particular type. It's a pretty standard helper function, which uses DarwinCSV * and setCurrentCSV(...) to make file loading happen with messaging and whatnot. We can also * reset the display: just call loadFile(null). * * @param file The file to load. * @param type The type of file (see DarwinCSV's constants). */ private void loadFile(File file, short type) { // If the file was reset, reset the display and keep going. if (file == null) { mainFrame.setTitle(basicTitle); setCurrentCSV(null); return; } // Load up a new DarwinCSV and set current CSV. try { setCurrentCSV(new DarwinCSV(file, type)); } catch (IOException ex) { MessageBox.messageBox( mainFrame, "Could not read file '" + file + "'", "Unable to read file '" + file + "': " + ex); } // Set the main frame title, based on the filename and the index. mainFrame.setTitle( basicTitle + ": " + file.getName() + " (" + String.format("%,d", currentCSV.getRowIndex().getRowCount()) + " rows)"); }
public static void main(String[] args) { JFrame frame = new JFrame("Maze View"); Random random = new Random(); long startTime = System.nanoTime(); MazeNode maze = MazeNode.generate(random, 100, 100); System.out.println("Gen : " + elapsedMs(startTime) + "ms"); startTime = System.nanoTime(); int sx = 0; // random.nextInt(maze.width); int sy = 0; // random.nextInt(maze.height); int dx = maze.width - 1; // random.nextInt(maze.width); int dy = maze.height - 1; // random.nextInt(maze.height); Path path = PathSolver.solve(maze, sx, sy, dx, dy); System.out.println("Solve : " + elapsedMs(startTime) + "ms"); int pathSize = 0; PathCell pathIt = path.first; while (pathIt != null) { pathSize++; pathIt = pathIt.next; } System.out.println("Path Size: " + pathSize); frame.add(new JScrollPane(new MazeView(maze, sx, sy, dx, dy, path))); frame.setSize(500, 500); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); SwingUtilities.invokeLater(() -> frame.setVisible(true)); }
public static void main(String[] args) { JFrame mainFrame = new JFrame("TestPopupWindow"); mainFrame.getContentPane().add(new TestPopupWindow()); mainFrame.pack(); mainFrame.setLocationRelativeTo(null); mainFrame.setVisible(true); }
public static void main(String[] args) { JFrame gameWindow = new JFrame("Tic Tac Toe"); gameWindow.add(new TicTacToeGame()); gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gameWindow.pack(); gameWindow.setVisible(true); }
public void testContextIsJFrameWhenJFrameIsShown() { JFrame frame = new JFrame(); JButton comp = new JButton(); frame.getContentPane().add(comp); windowContext.setActiveWindow(comp); assertSame(frame, windowContext.activeWindow()); }
/** 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); }
private static void constructMenu() { final JFrame lFrame = (JFrame) viewModel.get("window.frame"); final JMenuBar lMenuBar = new JMenuBar(); lFrame.setJMenuBar(lMenuBar); viewModel.put("menu", lMenuBar); final JMenu lFileMenu = new JMenu("File"); lFileMenu.setMnemonic(KeyEvent.VK_F); viewModel.put("menu.file", lFileMenu); lMenuBar.add(lFileMenu); final JMenuItem lExitItem = new JMenuItem((Action) viewModel.get("action.exit")); viewModel.put("menu.file.exit", lExitItem); lFileMenu.add(lExitItem); final JMenuItem lHelpMenu = new JMenu("Help"); lHelpMenu.setMnemonic(KeyEvent.VK_H); viewModel.put("menu.help", lHelpMenu); lMenuBar.add(lHelpMenu); final JMenuItem lHelpTopicsItem = new JMenuItem((Action) viewModel.get("action.help")); viewModel.put("menu.help.topics", lHelpTopicsItem); lHelpMenu.add(lHelpTopicsItem); final JMenuItem lAboutItem = new JMenuItem((Action) viewModel.get("action.about")); viewModel.put("menu.help.about", lAboutItem); lHelpMenu.add(lAboutItem); }
public void setUpGui() { m1 = new MyDrawPanel(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setContentPane(m1); f.setBounds(30, 30, 300, 300); f.setVisible(true); } // quit meth
public void init(Controller c) { super.init(c); // Make the Display2D. We'll have it display stuff later. display = new Display2D(500, 500, this, 1); // at 400x400, we've got 4x4 per array position displayFrame = display.createFrame(); c.registerFrame(displayFrame); // register the frame so it appears in the "Display" list displayFrame.setVisible(true); // attach the portrayals from bottom to top display.attach(foodPortrayal, "Food"); display.attach(agentPortrayal, "Agents"); displayFrame.setTitle("Agents"); // specify the backdrop color -- what gets painted behind the displays display.setBackdrop(Color.yellow); // Make the Display2D. We'll have it display stuff later. display2 = new Display2D(400, 400, this, 1); // at 400x400, we've got 4x4 per array position displayFrame2 = display2.createFrame(); displayFrame2.setTitle("Statistic"); c.registerFrame(displayFrame2); // register the frame so it appears in the "Display" list displayFrame2.setVisible(false); // specify the backdrop color -- what gets painted behind the displays display2.setBackdrop(Color.GRAY); // attach the portrayals from bottom to top display2.attach(summaryPortrayal, "Summary"); }
public static void main(final String[] args) { JFrame frame = new JFrame("Credit calculator"); frame.setContentPane(new HypothecCalculator().mainPanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
public void create() { JFrame frame = new JFrame(); frame.getContentPane().add(new JScrollPane(jgraph)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
public void go() { frame = new JFrame("Quiz Card Player"); JPanel mainPanel = new JPanel(); Font bigFont = new Font("sanserif", Font.BOLD, 24); display = new JTextArea(10, 20); display.setFont(bigFont); display.setLineWrap(true); display.setEditable(false); JScrollPane qScroller = new JScrollPane(display); qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); nextButton = new JButton("Show Questions"); nextButton.addActionListener(new NextCardListener()); mainPanel.add(qScroller); mainPanel.add(nextButton); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenuItem loadMenuItem = new JMenuItem("Load Card Set"); loadMenuItem.addActionListener(new OpenMenuListener()); fileMenu.add(loadMenuItem); menuBar.add(fileMenu); frame.setJMenuBar(menuBar); frame.getContentPane().add(BorderLayout.CENTER, mainPanel); frame.setSize(640, 500); frame.setVisible(true); }