我认为您的问题在这里:
try { gd.setFullScreenWindow(this);}finally { gd.setFullScreenWindow(null);}finally块总是执行,所以这里发生的是,您的窗口在短时间内(如果有的话)变为全屏,然后立即放弃了屏幕。
另外,根据Javadocs,
setVisible(true)当您先前调用时,也没有必要。
setFullScreenWindow(this)
所以我将构造函数更改为:
public FullScreenframe() { addKeyListener(this); GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); if (gd.isFullScreenSupported()) { setUndecorated(true); gd.setFullScreenWindow(this); } else { System.err.println("Full screen not supported"); setSize(100, 100); // just something to let you see the window setVisible(true); }}


