java中如何进行全屏模式和窗口模式的转换 详细�0�3
1个回答
展开全部
java 中如何进行全屏模式和窗口模式的转换 代码如下所示: import java.awt.Dimension; import java.awt.DisplayMode; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; @SuppressWarnings("serial") public class WindowModelSample extends JFrame { public WindowModelSample() { super("窗口/全屏模式转换例子"); final JPanel panel = new JPanel(); final JButton button = new JButton("切换模式"); panel.setLocation(0, 0); Dimension dimension = new Dimension(1024, 768); panel.setSize(dimension); panel.setMaximumSize(dimension); panel.setMinimumSize(dimension); panel.setPreferredSize(dimension); panel.setLayout(null); button.addActionListener(new ActionListener() { boolean isWindowModel = true; @Override public void actionPerformed(ActionEvent e) { if ((isWindowModel = !isWindowModel)) { // 切换为窗口模式 WindowModelSample.this.dispose(); WindowModelSample.this.setUndecorated(false); WindowModelSample.this.getGraphicsConfiguration().getDevice().setFullScreenWindow(nu ll); WindowModelSample.this.setVisible(true); } else { // 切换为全屏独占模式 WindowModelSample.this.dispose(); WindowModelSample.this.setUndecorated(true); WindowModelSample.this.getGraphicsConfiguration().getDevice().setFullScreenWindow(W indowModelSample.this); WindowModelSample.this.getGraphicsConfiguration().getDevice().setDisplayMode(new DisplayMode(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height, 16, DisplayMode.REFRESH_RATE_UNKNOWN)); WindowModelSample.this.repaint(); } } }); button.setBounds(100, 100, 100, 100); panel.add(button); setResizable(false); setLayout(null); setDefaultCloseOperation(EXIT_ON_CLOSE); setContentPane(panel); pack(); setLocationRelativeTo(null); setVisible(true); } public static void main(String[] args) { new WindowModelSample(); } } 上边这段代码就是关于窗口模式和全屏模式之间的切换代码,匆忙之间写的,有点简陋。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询