FullScreenMode in Java

  • Ich habe das Buch "Developing games in Java" von David Brackeen verfolgt und in Kapitel 2 lehrt er, wie man den Vollbildmodus verwendet. Das Problem, das ich habe, ist, dass wenn ich seinen Quellcode laufen lasse, alles, was ich bekomme, ein weißer Bildschirm ist. Ich habe Stunden damit verbracht und glaube, es hat etwas mit Windows 7 zu tun.

    Vielen Dank für Ihre Zeit!

     import java.awt.*;
    
    import javax.swing.JFrame;
    
    /**
    The SimpleScreenManager class manages initializing and
    displaying full screen graphics modes.
    */
    public class SimpleScreenManager {
    
    private GraphicsDevice device;
    
    /**
        Creates a new SimpleScreenManager object.
    */
    public SimpleScreenManager() {
        GraphicsEnvironment environment =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        device = environment.getDefaultScreenDevice();
    
    }
    
    
    /**
        Enters full screen mode and changes the display mode.
    */
    public void setFullScreen(DisplayMode displayMode,
        JFrame window)
    {
        window.setUndecorated(true);
        window.setResizable(false);
    
        device.setFullScreenWindow(window);
    
        if (displayMode != null &&
            device.isDisplayChangeSupported())
        {
            try {
                device.setDisplayMode(displayMode);
            }
            catch (IllegalArgumentException ex) {
                // ignore - illegal mode for this device
            }
        }
    }
    
    
    /**
        Returns the window currently used in full screen mode.
    */
    public Window getFullScreenWindow() {
        return device.getFullScreenWindow();
    }
    
    
    /**
        Restores the screen's display mode.
    */
    public void restoreScreen() {
        Window window = device.getFullScreenWindow();
        if (window != null) {
            window.dispose();
        }
        device.setFullScreenWindow(null);
    }
    
    public static void main(String args[])
    {
        SimpleScreenManager t = new SimpleScreenManager();
        try {
    
            t.setFullScreen(new DisplayMode(1920, 1080, 64, 0), new JFrame());
            Thread.sleep(2000);
        }
         catch (InterruptedException ex) { }
        finally {
            t.restoreScreen();
        }
    }
     

    }

    22 November 2011
    MByD
1 answer
  • Umschalten! umschalten ...

     private void toggleDecoration(boolean decorated) {
        dispose();
        if (decorated) {
            //save last bounds and its extended state
            lastState = getExtendedState();
            lastBounds = getBounds();
            try{
                setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
            }
            catch(Exception ev){
                setBounds(getGraphicsConfiguration().getDevice().getDefaultConfiguration().getBounds());
                ev.printStackTrace();
            }
        }
        else {
            //restore last bounds and its extended state
            setBounds(lastBounds);
            setExtendedState(lastState);
        }
        setUndecorated(decorated);
        setVisible(true);
    }
     
    22 November 2011
    ecle