Javaで全画面表示する方法です。GraphicsDeviceのsetFullScreenWindow メソッドの引数に全画面表示させたいWindowオブジェクトを渡すことで実現できます。サンプルコードを以下に示します。
全画面表示を終了させるときは、GraphicsDeviceにnullをセットします。
例えばこんな感じで使います。
public static GraphicsDevice setFullScreen(Window window) {
GraphicsDevice graphicsDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
graphicsDevice.setFullScreenWindow(window);
return graphicsDevice; // not necessary to return but... easy to reuse GraphicsDevice object after this method is called
}
全画面表示を終了させるときは、GraphicsDeviceにnullをセットします。
GraphicsEnvironment .getLocalGraphicsEnvironment() .getDefaultScreenDevice() .graphicsDevice.setFullScreenWindow(null);
例えばこんな感じで使います。
public class FullScreenTest {
@Test
public void testFullScreen() throws Exception {
JWindow window = createTestWindow();
window.setVisible(true);
GraphicsDevice graphicsDevice = AwtUtils.setFullScreen(window);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
graphicsDevice.setFullScreenWindow(null);
window.dispose();
}
private static JWindow createTestWindow() {
return new JWindow(){
public void paint(Graphics graphics)
{
super.paint(graphics);
graphics.setColor(Color.blue);
graphics.setFont(new Font(null, Font.BOLD, 80));
graphics.drawString("Hello, World!", 40, 100);
}
};
}
}
コメント