java窗体返回参数,全屏及返回窗口化,全屏返回窗口化,应用 java.awt.

全屏及返回窗口化,全屏返回窗口化,应用 java.awt.

应用 java.awt.GraphicsDevice类

public void setFullScreenWindow( Windoww);进入全屏模式,或返回窗口化模式。进入的全屏模式可以是独占的,也可以是模拟的。只有 isFullScreenSupported 返回 true时,独占模式才可用。

参数:

w - 一个用作全屏窗口的窗口;如果返回到窗口化模式,则为 null。一些平台希望全屏窗口成为顶层组件(即 Frame);因此这里最好使用Frame,而不用 Window。package fullscreen;import java.awt.FlowLayout;import java.awt.GraphicsDevice;import java.awt.GraphicsEnvironment;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.lang.reflect.InvocationTargetException;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.SwingUtilities;public class FullScreen1 { public FullScreen1(){ final JFrame jframe = new JFrame(); JButton fullsButton = new JButton("全屏显示"); JButton windowButton = new JButton("退出全屏"); JButton exitButton = new JButton("退出"); exitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { System.exit(1); } }); windowButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null); } }); jframe.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // TODO Auto-generated method stub super.windowClosing(e); System.exit(0); } }); fullsButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { /** * 第一种方法 */ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); //通过调用GraphicsEnvironment的getDefaultScreenDevice方法获得当前的屏幕设备了 GraphicsDevice gd = ge.getDefaultScreenDevice(); // 全屏设置 gd.setFullScreenWindow(jframe); /** * 第二种方法 */ /*Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle bounds = new Rectangle(screenSize); jframe.setBounds(bounds);*/ } }); jframe.add(fullsButton); jframe.add(exitButton); jframe.add(windowButton); jframe.setLayout(new FlowLayout()); jframe.setSize(400, 300); jframe.setVisible(true); } public static void main(String[] args) throws InvocationTargetException, InterruptedException { SwingUtilities.invokeAndWait(new Runnable(){ @Override public void run() { new FullScreen1(); } }); }}//该片段来自于http://byrx.net

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值