The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.awt  [78 examples] > The Screen  [8 examples]

e601. Enabling Full-Screen Mode

In full-screen mode, no window can overlap the full-screen window. Also, when in full-screen mode, the display mode typically can be changed if desired (see e605 Setting the Screen Size, Refresh Rate, or Number of Colors).
    // Determine if full-screen mode is supported directly
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gs = ge.getDefaultScreenDevice();
    if (gs.isFullScreenSupported()) {
        // Full-screen mode is supported
    } else {
        // Full-screen mode will be simulated
    }
    
    // Create a button that leaves full-screen mode
    Button btn = new Button("OK");
    btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            // Return to normal windowed mode
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice gs = ge.getDefaultScreenDevice();
            gs.setFullScreenWindow(null);
        }
    });
    
    // Create a window for full-screen mode; add a button to leave full-screen mode
    Frame frame = new Frame(gs.getDefaultConfiguration());
    Window win = new Window(frame);
    win.add(btn, BorderLayout.CENTER);
    
    try {
        // Enter full-screen mode
        gs.setFullScreenWindow(win);
        win.validate();
    
        // ...
    } finally {
        // Exit full-screen mode
        gs.setFullScreenWindow(null);
    }

 Related Examples
e598. Getting the Screen Size
e599. Centering a Frame, Window, or Dialog on the Screen
e600. Getting the Number of Screens
e602. Double-Buffering in Full-Screen Mode
e603. Getting the Available Screen Sizes, Refresh Rates, and Number of Colors
e604. Getting the Current Screen Refresh Rate and Number of Colors
e605. Setting the Screen Size, Refresh Rate, or Number of Colors

See also: Colors    Components    Containers    Cursors    Drawing    Events    Focus    Frames    GridBagLayout    Images    Shapes    Simulating Events    Text   


© 2002 Addison-Wesley.