• 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 }

    转自网络!感谢分享!

  • 相关阅读:
    Java中的四种内部类
    用输入/输出写一个程序,让用户输入一些姓名和电话号码
    分批读取大数据问题
    Linux产生序列数字
    两个有序链表的合并
    int和Integer的区别
    wait()和sleep()的区别
    Unix和Windows文件格式转化
    截取字符串的代码实现
    查看系统信息
  • 原文地址:https://www.cnblogs.com/Acmen/p/2198245.html
Copyright © 2020-2023  润新知