Change Java screen resolution

I follow a series of tutorials for developing games in Java by thenewboston on Youtube. I am at a point where I can create a full-screen window, but the resolution refuses to resize to 800x600. I tested vc, the GraphicsEnvironment.getDefaultScreenDevice object and dm, DisplayMode, and they don't seem to be a 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");} } } 
+6
source share
1 answer

Add this code to your Core.java class (or GameClient.java). Perhaps the problem is 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 assume the error is related to your public void method setFullScreen (DisplayMode dm). In this 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 that it was a soft delivery after publication. Aaahh ...

+1
source

Source: https://habr.com/ru/post/908296/


All Articles