2017-08-16 59 views
1

我一直在使用這個代碼在屏幕上手動設置我的顯示器的像素尺寸:如何JFrame的設置全屏

public static void main(String[] args) { 
     Game game = new Game("ColoursAndShapes", 1920, 970); 
     game.start(); 
} 

我想找到一種方法來設置的JFrame到全屏任意監視器上,但考慮到我的「遊戲」類包含其他方法和變量,我無法從此啓動程序代碼中刪除它。

+2

你讀這https://stackoverflow.com/questions/11570356/jframe-in-full-screen-java –

回答

1
JFrame JFrame = new JFrame(); 
frame.setExtendedState(JFrame.MAXIMIZED_BOTH); frame.setUndecorated(true); 
frame.setVisible(true); 
+0

雖然這個代碼片斷可以解決的問題,[包括說明](//元.stackexchange.com/questions/114762/explain-completely-code-based-answers)確實有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。也請儘量不要用解釋性註釋來擠佔代碼,這會降低代碼和解釋的可讀性! – rene