public synchronized void toggleFullScreen() { if (inFullScreen) { this.dispose(); gd.setFullScreenWindow(null); canvas.setSize(NES_HEIGHT * screenScaleFactor, NES_WIDTH * screenScaleFactor); this.setUndecorated(false); this.setVisible(true); inFullScreen = false; buildMenus(); // nes.resume(); } else { setJMenuBar(null); gd = getGraphicsConfiguration().getDevice(); if (!gd.isFullScreenSupported()) { // then fullscreen will give a window the size of the screen instead messageBox("Fullscreen is not supported by your OS or version of Java."); } this.dispose(); this.setUndecorated(true); gd.setFullScreenWindow(this); this.setVisible(true); inFullScreen = true; } }
/** * ZombieFrame's constructor. * * @param contents Optional JPanel(s) to add to content pane. Arguments > 0 are ignored. */ public ZombieFrame(JPanel... contents) { super("ZombieHouse"); // Request keyboard focus for the frame. setFocusable(true); requestFocusInWindow(); requestFocus(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setUndecorated(true); setResizable(false); setBackground(Color.BLACK); // The content pane. An optional JPanel may be passed into the // constructor. It creates an empty pane with a black background if // one isn't provided. pane = getContentPane(); pane.setBackground(Color.BLACK); pane.setFocusable(false); pane.setVisible(true); if (contents.length > 0) { pane.add(contents[0]); } keys = new ZombieKeyBinds((JComponent) pane); // Get the graphics device information. GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice graphics = environment.getDefaultScreenDevice(); pack(); // Go full screen, if supported. if (graphics.isFullScreenSupported()) { try { graphics.setFullScreenWindow(this); // Having gone full screen, retrieve the display size. // size = Toolkit.getDefaultToolkit().getScreenSize(); // This double-switching of setVisible is to fix a bug with // full-screen-exclusive mode on OS X. Versions 10.8 and later // don't send keyboard events properly without it. if (System.getProperty("os.name").contains("OS X")) { setVisible(false); } } catch (HeadlessException ex) { System.err.println( "Error: primary display not set or found. " + "Your experience of life may be suboptimal."); ex.printStackTrace(); } } else { // If full-screen-exclusive mode isn't supported, switch to // maximized window mode. System.err.println("Full-screen-exclusive mode not supported."); setExtendedState(Frame.MAXIMIZED_BOTH); } setVisible(true); }
@Override public void start() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); gd = ge.getDefaultScreenDevice(); if (!gd.isFullScreenSupported()) { onError("Full-screen exclusive mode not supported"); System.exit(0); } // switch on FSEM // gd.setFullScreenWindow(window); window.setVisible(true); renderThread.start(); updateThread.start(); inputThread.start(); }
public static void toFullScreen( JFrame window, GraphicsDevice gd, boolean tryAppleFullscreen, boolean tryExclusiveFullscreen) { if (appleEawtAvailable() && tryAppleFullscreen && appleOSVersion() >= 7 && // lion and above javaVersion() >= 7) { // java 7 and above System.out.println("trying to apple fullscreen"); enableAppleFullscreen(window); doAppleFullscreen(window); } else if (appleEawtAvailable() && // Snow Leopard and below OR apple java 6 and below TODO: test this on SL tryExclusiveFullscreen && gd.isFullScreenSupported()) { if (javaVersion() >= 7) setAutoRequestFocus(window, true); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setUndecorated(true); // window.setExtendedState(JFrame.MAXIMIZED_BOTH); gd.setFullScreenWindow(window); window.toFront(); Rectangle r = gd.getDefaultConfiguration().getBounds(); window.setBounds(r); // window.pack(); } else { // Windows and Linux TODO: test this window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setUndecorated(true); window.setSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight()); window.setLocation(0, 0); window.setExtendedState(JFrame.MAXIMIZED_BOTH); window.toFront(); } window.pack(); window.setVisible(true); }