栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

全屏显示单个组件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

全屏显示单个组件

这是我的课程内置的示例,效果非常好。我确定我没有正确配置和验证框架,因此请对其进行评论,以便我进行更新。

public class FullScreenExample extends Jframe {    public class FullScreen {        private GraphicsDevice device;        private Jframe frame;        private boolean isFullScreen;        public FullScreen() { frame = new Jframe(); JPanel content = new JPanel(); content.setLayout(new BorderLayout()); frame.setContentPane(content); frame.setUndecorated(true); // Full screen escape frame.addKeyListener(new KeyListener() {     @Override     public void keyPressed(KeyEvent e) {         // Exit full screen when ESC pressed         if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {  exitFullScreen();         }     }     @Override     public void keyReleased(KeyEvent e) {}     @Override     public void keyTyped(KeyEvent e) {} });        }        public void enterFullScreen() { if (!isFullScreen) {     // Get the current device     GraphicsConfiguration config = FullScreenExample.this.getGraphicsConfiguration();     device = config.getDevice();     // Remove the panel from the wrapper     myWrapper.remove(myPanel);     // Add the panel to the full screen frame     frame.getContentPane().add(myPanel);     // Set the full screen window     device.setFullScreenWindow(frame);     isFullScreen = true; }        }        public void exitFullScreen() { if (isFullScreen) {     // Remove the fractal from the full screen frame     frame.getContentPane().remove(myPanel);     // Add the panel back to the wrapper     myWrapper.add(myPanel);     // Disable full screen     device.setFullScreenWindow(null);     // Dispose frame     frame.dispose();     // Revalidate window     FullScreenExample.this.validate();     isFullScreen = false; }        }    }        private JPanel myPanel, myWrapper;    public static void main(String[] args) {        SwingUtilities.invokeLater(new Runnable() { @Override public void run() {     FullScreenExample frame = new FullScreenExample();     frame.init();     frame.setVisible(true); }        });    }    public void init() {        // Generate example main window        JPanel content = new JPanel();        content.setBorder(new EmptyBorder(5, 5, 5, 5));        content.setLayout(new BorderLayout());        this.setContentPane(content);        this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);        myPanel = new JPanel();        myPanel.setBackground(Color.BLUE);        // Full screen button and listener        JButton fullscreen = new JButton("Full Screen");        final FullScreen fs = new FullScreen();        fullscreen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) {     fs.enterFullScreen(); }        });        myWrapper = new JPanel();        myWrapper.setLayout(new BorderLayout());        myWrapper.add(myPanel);        content.add(myWrapper, BorderLayout.CENTER);        content.add(fullscreen, BorderLayout.SOUTH);        this.setBounds(100, 100, 350, 350);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/570808.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号