Walter Coggeshall
Walter Coggeshall

Reputation: 97

Java screen resolution change

I am following a series of tutorials on game development in Java by thenewboston on Youtube. I am at the point where I can make a fullscreen window, but the resolution refuses to resize to 800x600. I have tested vc, a GraphicsEnvironment.getDefaultScreenDevice object, and dm, a DisplayMode, and they don't seem to be the problem. I am running Snow Leopard. Any ideas?

if(dm != null && vc.isDisplayChangeSupported()){
        try{
            vc.setDisplayMode(dm);
            System.out.println("Display mode set");
        }catch(Exception ex){System.out.println("Despite the vc saying it is display change supported and the DM is not null, something went wrong");}

    }
}

Upvotes: 6

Views: 1224

Answers (1)

user1260503
user1260503

Reputation:

Add this code to your Core.java (or GameClient.java) class. The issue may be that you are not passing the required DM[] args to your ScreenManager.java class.

private static final DisplayMode modes[] = { //common monitor DMs 
    new DisplayMode(1366,768,32, DisplayMode.REFRESH_RATE_UNKNOWN), //1366x768px w/32-bit depth
    new DisplayMode(1366,768,24, DisplayMode.REFRESH_RATE_UNKNOWN), //    '      w/24-bit depth
    new DisplayMode(1366,768,16, DisplayMode.REFRESH_RATE_UNKNOWN), //    '      w/16-bit depth     
    new DisplayMode(800,600,32, DisplayMode.REFRESH_RATE_UNKNOWN),  //800x600px  w/32-bit depth
    new DisplayMode(800,600,24, DisplayMode.REFRESH_RATE_UNKNOWN),  //    '      w/24-bit depth
    new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN),  //    '      w/16-bit depth 
    new DisplayMode(640,480,32, DisplayMode.REFRESH_RATE_UNKNOWN),  //640x480px  w/32-bit depth
    new DisplayMode(640,480,24, DisplayMode.REFRESH_RATE_UNKNOWN),  //    '      w/24-bit depth
    new DisplayMode(640,480,16, DisplayMode.REFRESH_RATE_UNKNOWN),  //    '      w/16-bit depth
};

I'm assuming that the error is with your public void setFullScreen(DisplayMode dm) method. In that case, the full syntax for this method is:

/*****************************************************************************
 * @description: Creates window for program to run in, using appropriate DM
 * @param DisplayMode dm 
 */
    public void setFullScreen(DisplayMode dm){
        JFrame f = new JFrame();
        f.setUndecorated(true); //no titlebars/scroll bars etc.
        f.setIgnoreRepaint(true);
        f.setResizable(false); //user cannot resize window
        vc.setFullScreenWindow(f);

        if(dm!=null && vc.isDisplayChangeSupported()){ //if DM is changeable
            try {
                vc.setDisplayMode(dm);
            } catch (Exception e){/*Catch 'em all*/}
        }
        f.createBufferStrategy(2); //set # of screen buffers to 2
    }//setFullScreen()

Noticed this was a mild necro-post after posting. Aaahh...

Upvotes: 1

Related Questions