欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

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

来源: javaer 分享于  点击 44287 次 点评:153

全屏及返回窗口化,全屏返回窗口化,应用 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
相关栏目:

用户点评