public SimpleDialog(JFrame parent, String title, String message) { // Set default settings super(parent, title, true); if (parent != null) { Dimension parentSize = parent.getSize(); Point p = parent.getLocation(); setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4); } // The message is the contentPane JPanel messagePane = new JPanel(); messagePane.add(new JLabel(message)); getContentPane().add(messagePane); JPanel buttonPane = new JPanel(); // Add an "OK" button JButton button = new JButton("OK"); buttonPane.add(button); // Adding a listener to make the dialog box close when the "OK" button is clicked button.addActionListener(this); getContentPane().add(buttonPane, BorderLayout.SOUTH); setDefaultCloseOperation(DISPOSE_ON_CLOSE); pack(); // Make the dialog box visible setVisible(true); }
public static void main(String[] args) throws Exception { if (!OS.contains("mac")) { System.out.println("The test is applicable only to Mac OS X. Passed"); return; } // Move the mouse out, because it could interfere with the test. Robot r = Util.createRobot(); Util.waitForIdle(r); r.mouseMove(0, 0); Util.waitForIdle(r); SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { createAndShowGUI(); } }); // Move the mouse away from the frame and check the View-base full screen mode Util.waitForIdle(r); r.mouseMove(500, 500); Util.waitForIdle(r); mouseEnterCount = 0; SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .setFullScreenWindow(frame); } }); Util.waitForIdle(r); if (mouseEnterCount != 1) { throw new RuntimeException("No MouseEntered event for view-base full screen. Failed."); } SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .setFullScreenWindow(null); } }); // Test native full screen support Util.waitForIdle(r); Point fullScreenButtonPos = frame.getLocation(); fullScreenButtonPos.translate(frame.getWidth() - 10, 10); r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y); mouseEnterCount = 0; // Cant use waitForIdle for full screen transition. int waitCount = 0; while (!windowEnteringFullScreen) { r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); Thread.sleep(100); if (waitCount++ > 10) throw new RuntimeException("Can't enter full screen mode. Failed"); } waitCount = 0; while (!windowEnteredFullScreen) { Thread.sleep(200); if (waitCount++ > 10) throw new RuntimeException("Can't enter full screen mode. Failed"); } if (mouseEnterCount != 1) { throw new RuntimeException("No MouseEntered event for native full screen. Failed."); } }
public Point getLocation() { return jFrame.getLocation(); }
public void offsetPosition(int dx, int dy) { Point p = jFrame.getLocation(); jFrame.setLocation(p.x + dx, p.y + dy); }
public OptionsDialogOld(JFrame parent) { super(parent, true); game = new SurroundGame(10, 2, 1, 1); setTitle("Game Options"); setUndecorated(true); closeStatus = false; try { background = ImageIO.read( new File( "C:\\Users\\Frank\\" + "workspace\\Surround\\src\\package1\\" + "bcktile.png")); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Image not found"); } Font font2 = new Font("Cooper Black", Font.BOLD, 30); okButton = new JButton("OK"); okButton.setFont(font2); cancelButton = new JButton("CANCEL"); cancelButton.setFont(font2); okButton.addActionListener(this); cancelButton.addActionListener(this); JPanel container = new ImagePanel(background); container.setLayout(new BorderLayout()); JLabel title = new JLabel("Game Options", SwingConstants.CENTER); Font font = new Font("Cooper Black", Font.BOLD, 60); title.setFont(font); // title.setAlignmentX(CENTER_ALIGNMENT); container.add(BorderLayout.NORTH, title); JPanel panel = new JPanel(); panel.setName("Game Options"); panel.setLayout(new GridLayout(5, 2)); DefaultListCellRenderer dlcr = new DefaultListCellRenderer(); dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER); String[] board = { "4 x 4", "5 x 5", "6 x 6", "7 x 7", "8 x 8", "9 x 9", "10 x 10", "11 x 11", "12 x 12" }; boardBox = new JComboBox<String>(board); boardBox.setFont(font2); boardBox.setRenderer(dlcr); JLabel sizeLabel = new JLabel("Size of the board:"); sizeLabel.setFont(font2); panel.add(sizeLabel); panel.add(boardBox); String[] players = {"2", "3", "4", "5", "6", "7", "8", "9", "10"}; String[] turns = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; playersBox = new JComboBox<String>(players); playersBox.setFont(font2); playersBox.setRenderer(dlcr); JLabel playersLabel = new JLabel("Number of players:"); playersLabel.setFont(font2); panel.add(playersLabel); panel.add(playersBox); humansBox = new JComboBox<String>(turns); humansBox.setFont(font2); humansBox.setRenderer(dlcr); JLabel humansLabel = new JLabel("Number of human players:"); humansLabel.setFont(font2); panel.add(humansLabel); panel.add(humansBox); startBox = new JComboBox<String>(turns); startBox.setFont(font2); startBox.setRenderer(dlcr); JLabel startLabel = new JLabel("Starting player:"); startLabel.setFont(font2); panel.add(startLabel); panel.add(startBox); panel.add(okButton); panel.add(cancelButton); // container.setPreferredSize(new Dimension(700,700)); container.add(BorderLayout.CENTER, panel); panel.setOpaque(false); container.setOpaque(false); Box box = new Box(BoxLayout.Y_AXIS); box.add(Box.createVerticalGlue()); box.add(container); // box.setVisible(true); // setContentPane(background); // background. getContentPane().add(box); // add(box); // getContentPane().add(container); setAlwaysOnTop(true); setSize(parent.getSize()); setLocation(parent.getLocation()); setVisible(true); }