我无法找到全屏窗口的任何特定解决方案,所以我想问一下。如何在全屏窗口的顶部创建一个JOptionPane?
在这里,我将全屏窗口作为构造函数参数。但是当我按下ESC时,我的窗口将自己发送到后台,就像我按下了#Alt; Tab + Tab"。然后,如果我从开始菜单栏点击,我可以在窗口顶部看到它。但是我想结束这个发送背景问题。我该如何修复它?
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;
import java.awt.*;
public class KeyListenerTest extends JFrame implements KeyListener {
private Window windo;
private ImageIcon quitImage;
public KeyListenerTest(Window window)
{
quitImage = new ImageIcon("quitask.png");
windo = window;
addKeyListener(this);
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
JOptionPane opti = new JOptionPane();
int choice = opti.showConfirmDialog(windo, "Do you really want to quit?", "QUIT", JOptionPane.YES_NO_OPTION ,
JOptionPane.QUESTION_MESSAGE , quitImage);
opti.requestFocusInWindow();
if(choice == JOptionPane.YES_OPTION)
{
System.exit(0);
}
else
{
dispose();
System.out.println("ESC key typed");
}
}
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
}
这是我的窗口全屏显示的代码
window=(Window)frame;
window.setFocusable(true);
KeyListenerTest keyo = new KeyListenerTest(window);
frame.addKeyListener(keyo);
g.setFullScreenWindow(window);