我有以下代码,这将使窗口始终显示在用户关闭之前,即使我已经实现了焦点监听器,当焦点是我设置为始终顶部并且焦点重新获得时,这在视窗。在mac和linux用户可以切换到不同的桌面/屏幕,有没有办法复制窗口,如果用户在一个地方关闭,如果关闭一切(基本上是同步)。这不是kiosk应用程序,应用程序运行是普通用户机器,我想确保当我的应用程序提示然后用户应该输入并且他不应该逃避
import java.awt.event.*;
import javax.swing.*;
public class MainWindow extends JFrame implements WindowFocusListener
{
public MainWindow()
{
addWindowFocusListener(this);
setAlwaysOnTop(true);
this.setFocusable(true);
// this.setFocusableWindowState(true);
panel = new JPanel();
//setSize(WIDTH,HEIGHT);
setUndecorated(true);
setLocation(X,Y);
setExtendedState(MAXIMIZED_BOTH);
setVisible(true);
}
public void windowGainedFocus(WindowEvent e){}
public void windowLostFocus(WindowEvent e)
{
if(e.getNewState()!=e.WINDOW_CLOSED){
//toFront();
//requestFocus();
setAlwaysOnTop(false);
setAlwaysOnTop(true);
//requestFocusInWindow();
System.out.println("focus lost");
}
}
private JPanel panel;
private static final int WIDTH = 200;
private static final int HEIGHT = 200;
private static final int X = 100;
private static final int Y = 100;
public static void main(String args[]){
new MainWindow();}
}