日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Java JFrame实现全屏的四种方式

發(fā)布時(shí)間:2025/4/16 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java JFrame实现全屏的四种方式 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

JFrame實(shí)現(xiàn)全屏的四種方式,方式一:

  • import?java.awt.*;?
  • ?
  • import?javax.swing.*;?
  • ?
  • public?class?FullScreenDemo1?{?
  • ?
  • ????public?static?void?main(String[]?args)?{?
  • ????????final?JFrame?jframe?=?new?JFrame();?
  • ????????JButton?fullsButton?=?new?JButton("全屏顯示");?
  • ????????JButton?exitButton?=?new?JButton("退出");?
  • ????????exitButton.addActionListener(new?java.awt.event.ActionListener()?{?
  • ????????????public?void?actionPerformed(java.awt.event.ActionEvent?evt)?{?
  • ????????????????System.exit(1);?
  • ????????????}?
  • ????????});?
  • ????????fullsButton.addActionListener(new?java.awt.event.ActionListener()?{?
  • ????????????public?void?actionPerformed(java.awt.event.ActionEvent?evt)?{?
  • ????????????????GraphicsEnvironment?ge?=?GraphicsEnvironment.getLocalGraphicsEnvironment();?
  • ????????????????//通過調(diào)用GraphicsEnvironment的getDefaultScreenDevice方法獲得當(dāng)前的屏幕設(shè)備了?
  • ????????????????GraphicsDevice?gd?=?ge.getDefaultScreenDevice();?
  • ????????????????//?全屏設(shè)置?
  • ????????????????gd.setFullScreenWindow(jframe);?
  • ????????????}?
  • ????????});?
  • ????????jframe.add(fullsButton);?
  • ????????jframe.add(exitButton);?
  • ????????jframe.setLayout(new?FlowLayout());?
  • ????????jframe.setSize(400,?300);?
  • ????????jframe.setVisible(true);?
  • ????}?
  • }?
  • 方式二:

  • import?java.awt.FlowLayout;?
  • ?
  • import?javax.swing.JButton;?
  • import?javax.swing.JFrame;?
  • import?javax.swing.UIManager;?
  • ?
  • public?class?FullScreenDemo2?{?
  • ?
  • ????public?static?void?main(String[]?args)?{?
  • ????????JFrame?jframe?=?new?JFrame();?
  • ????????JButton?exitButton?=?new?JButton("退出");?
  • ????????exitButton.addActionListener(new?java.awt.event.ActionListener()?{?
  • ????????????public?void?actionPerformed(java.awt.event.ActionEvent?evt)?{?
  • ????????????????System.exit(1);?
  • ????????????}?
  • ????????});?
  • ????????jframe.add(exitButton);?
  • ????????jframe.setLayout(new?FlowLayout());?
  • ????????jframe.setUndecorated(false);?
  • ????????jframe.getGraphicsConfiguration().getDevice()?
  • ????????????????.setFullScreenWindow(jframe);?
  • ????????jframe.setVisible(true);?
  • ????}?
  • }?
  • 方式三:

  • import?java.awt.Dimension;?
  • import?java.awt.FlowLayout;?
  • import?java.awt.Toolkit;?
  • ?
  • import?javax.swing.JButton;?
  • import?javax.swing.JFrame;?
  • ?
  • public?class?FullScreenDemo3?{?
  • ????public?static?void?main(String[]?args)?{?
  • ????????JFrame?jframe?=?new?JFrame();?
  • ????????JButton?exitButton?=?new?JButton("退出");?
  • ????????exitButton.addActionListener(new?java.awt.event.ActionListener()?{?
  • ????????????public?void?actionPerformed(java.awt.event.ActionEvent?evt)?{?
  • ????????????????System.exit(1);?
  • ????????????}?
  • ????????});?
  • ????????jframe.add(exitButton);?
  • ????????jframe.setLayout(new?FlowLayout());?
  • ????????/**?
  • ?????????*?true無邊框?全屏顯示?
  • ?????????*?false有邊框?全屏顯示?
  • ?????????*/?
  • ????????jframe.setUndecorated(false);?
  • ????????Dimension?d?=?Toolkit.getDefaultToolkit().getScreenSize();?
  • ????????jframe.setSize(d.width,?d.height);?
  • ????????jframe.setVisible(true);?
  • ????}?
  • }?
  • 方式四:

  • import?java.awt.Dimension;?
  • import?java.awt.FlowLayout;?
  • import?java.awt.Rectangle;?
  • import?java.awt.Toolkit;?
  • ?
  • import?javax.swing.JButton;?
  • import?javax.swing.JFrame;?
  • public?class?FullScreenDemo3?{?
  • ?
  • ????public?static?void?main(String[]?args)?{?
  • ????????JFrame?jframe?=?new?JFrame();?
  • ????????JButton?exitButton?=?new?JButton("退出");?
  • ????????exitButton.addActionListener(new?java.awt.event.ActionListener()?{?
  • ?
  • ????????????public?void?actionPerformed(java.awt.event.ActionEvent?evt)?{?
  • ????????????????System.exit(1);?
  • ????????????}?
  • ????????});?
  • ????????jframe.add(exitButton);?
  • ????????jframe.setLayout(new?FlowLayout());?
  • ????????/**?
  • ?????????*?true無邊框?全屏顯示?
  • ?????????*?false有邊框?全屏顯示?
  • ?????????*/?
  • ????????jframe.setUndecorated(false);?
  • ????????Dimension?screenSize?=?Toolkit.getDefaultToolkit().getScreenSize();?
  • ????????Rectangle?bounds?=?new?Rectangle(screenSize);?
  • ????????jframe.setBounds(bounds);?
  • ????????jframe.setExtendedState(JFrame.MAXIMIZED_BOTH);?
  • ????????jframe.setVisible(true);?
  • ????}?
  • }
  • 總結(jié)

    以上是生活随笔為你收集整理的Java JFrame实现全屏的四种方式的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。