当只有一个窗口时,在java中切换全屏和dispose()的行为

时间:2016-01-01 10:51:45

标签: java awt

这个问题是关于java中的dispose()方法。 我试图实现一个窗口类,我希望能够在全屏独占模式和普通窗口模式之间切换。 根据此this site的实现,您可以处置()一个帧并再次重用它。但根据java docs,这可能导致VM终止(因为它是我将使用的唯一窗口)。

根据网站的实现是一个坏主意还是我误解了dispose()的行为?

网站上的代码:

//set the display mode back to the what it was when
//the program was launched.
device.setDisplayMode(dispModeOld);

//hide the frame so we can change it.
setVisible(false);

//remove the frame from being displayable.
dispose();

//put the borders back on the frame.
setUndecorated(false);

//needed to unset this window as the fullscreen window.
device.setFullScreenWindow(null);

//make sure the size of the window is correct.
setSize(800,600);

//recenter window
setLocationRelativeTo(null);

//reset the display mode to what it was before
//we changed it.
setVisible(true);

0 个答案:

没有答案