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

如何在Java中以全屏独占模式处理来自键盘和鼠标的事件?

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

如何在Java中以全屏独占模式处理来自键盘和鼠标的事件?

它看起来像“如何使用键绑定”和“如何编写鼠标侦听器”中所示的常规方法在全屏独占模式下正常工作。

import java.awt.Color;import java.awt.EventQueue;import java.awt.GraphicsDevice;import java.awt.GraphicsEnvironment;import java.awt.event.ActionEvent;import java.awt.event.KeyEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.WindowEvent;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.JButton;import javax.swing.Jframe;import javax.swing.JPanel;import javax.swing.KeyStroke;public class FullScreenTest extends JPanel {    private static final String EXIT = "Exit";    private Jframe f = new Jframe("FullScreenTest");    private Action exit = new AbstractAction(EXIT) { @Override public void actionPerformed(ActionEvent e) {     f.dispatchEvent(new WindowEvent(         f, WindowEvent.WINDOW_CLOSING)); }        };    private JButton b = new JButton(exit);    public FullScreenTest() {        this.add(b);        f.getRootPane().setDefaultButton(b);        this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0), EXIT);        this.getActionMap().put(EXIT, exit);        this.addMouseMotionListener(new MouseAdapter() { @Override public void mouseMoved(MouseEvent e) {     FullScreenTest.this.setToolTipText(         "("+ e.getX() + "," + e.getY() + ")"); }        });    }    private void display() {        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();        GraphicsDevice dev = env.getDefaultScreenDevice();        f.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);        f.setBackground(Color.darkGray);        f.setResizable(false);        f.setUndecorated(true);        f.add(this);        f.pack();        dev.setFullScreenWindow(f);    }    public static void main(String[] args) {        EventQueue.invokeLater(new Runnable() { @Override public void run() {     new FullScreenTest().display(); }        });    }}


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

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

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