JAVA全屏模式

 1     import java.awt.DisplayMode;  
2 import java.awt.FlowLayout;
3 import java.awt.GraphicsDevice;
4 import java.awt.GraphicsEnvironment;
5 import java.awt.Insets;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8
9 import javax.swing.JButton;
10 import javax.swing.JFrame;
11
12 public class FullScreenDemo {
13 public static void main(String[] args) {
14 JFrame window = new JFrame();
15
16 window.setUndecorated(true);
17 window.setResizable(false);
18 window.setLayout(new FlowLayout());
19 JButton button = new JButton("close window");
20 button.setMargin(new Insets(0, 0, 0, 0));
21 button.addActionListener(new ActionListener() {
22 @Override
23 public void actionPerformed(ActionEvent e) {
24 System.exit(0);
25 }
26 });
27 window.add(button);
28
29 DisplayMode displayMode = new DisplayMode(1440,900,32,75);//分辨率800*600,16色深,75HZ
30 /*
31 * 下面为主要的设置全屏
32 */
33 GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
34 GraphicsDevice device = environment.getDefaultScreenDevice();
35 //use the Jframe as the full screen window
36 device.setFullScreenWindow(window);
37 //如果要退出全屏
38 //device.setFullScreenWindow(null);
39 //change the displaymode
40 if(displayMode != null && device.isDisplayChangeSupported()){
41 try {
42 device.setDisplayMode(displayMode);
43 } catch (Exception e) {
44 }
45 }
46
47 }
48 }

转自网络!感谢分享!

原文地址:https://www.cnblogs.com/Acmen/p/2198245.html