Java全屏程序(Swing)-Tab/ALT F4

问题描述:

我需要一种方法来阻止人们在我的Java程序运行时使用其他程序。即阻止人们切换标签,按下ALT + F4 ...Java全屏程序(Swing)-Tab/ALT F4

谢谢:)

+0

我不认为你可以这样做,而不诉诸依赖于平台的JNI。一个很好的问题。 – 2010-12-16 15:37:35

+3

你为什么要这么做?运行多任务操作系统的重点在于人们可以做到这一点。 – DJClayworth 2010-12-16 15:54:59

+0

看看:http://*.com/questions/6127709/remove-the-possibility-of-using-alt-f4-and-alt-tab-in-java-gui?lq=1 – seewip 2012-07-25 14:06:57

为了使程序全屏使用;

window.setExtendedState(Frame.MAXIMIZED_BOTH); //maximise window 

window.setUndecorated(true); //remove decorations e.g. x in top right 

并使窗口始终处于最佳使用状态(阻止使用其他正在运行的程序的人员);

window.setAlwaysOnTop(true); 
+0

谢谢Ste T :) – 2010-12-16 15:41:10

+0

最大化窗口是否阻止访问窗口任务栏?如果你的窗口始终处于最佳状态,它是否会掩盖后面可能会出现的任何模态对话框? – Curtis 2010-12-16 15:41:16

+3

如果窗口失去焦点,任务栏确实变得可见,但是您可以使用机器人在窗口失去焦点时单击以进行修复:D – 2010-12-16 15:45:27

您不能在Java级别上做到这一点 - 您需要将操作系统设置为某种“Kiosk模式”。

不请自来的评论 - 你是否需要这个,是因为你(或你的客户)讨厌你的用户,并希望他们永远诅咒你?您是否打算将“关闭计算机”功能添加到您的程序中?

+9

+1为未经请求的评论。我会很快卸载这样一个程序。 – 2010-12-16 15:42:58

+6

也许这是某种公共终端或某种程序。我很难想象为什么在普通的台式电脑或笔记本电脑上需要这样的程序。 – 2010-12-16 15:56:56

如果您正在寻找全屏支持,这是我使用的代码。应该足以让你走了。您只需要一个全局布尔变量来说明应用程序是否全屏。你可以用它来修补它,让它显示你喜欢的。

 
/** 
    * Method allows changing whether this window is displayed in fullscreen or 
    * windowed mode. 
    * @param fullscreen true = change to fullscreen, 
    *     false = change to windowed 
    */ 
    public void setFullscreen(boolean fullscreen) 
    { 
     //get a reference to the device. 
     GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); 
     DisplayMode dispMode = device.getDisplayMode(); 
     //save the old display mode before changing it. 
     dispModeOld = device.getDisplayMode(); 

     if(this.fullscreen != fullscreen) 
     { //are we actually changing modes. 
      //change modes. 
      this.fullscreen = fullscreen; 
      // toggle fullscreen mode 
      if(!fullscreen) 
      { 
       //change to windowed mode. 
       //set the display mode back to the what it was when 
       //the program was launched. 
       device.setDisplayMode(dispModeOld); 
       //hide the frame so we can change it. 
       setVisible(false); 
       //remove the frame from being displayable. 
       dispose(); 
       //put the borders back on the frame. 
       setUndecorated(false); 
       //needed to unset this window as the fullscreen window. 
       device.setFullScreenWindow(null); 
       //recenter window 
       setLocationRelativeTo(null); 
       setResizable(true); 

       //reset the display mode to what it was before 
       //we changed it. 
       setVisible(true); 

      } 
      else 
      { //change to fullscreen. 
       //hide everything 
       setVisible(false); 
       //remove the frame from being displayable. 
       dispose(); 
       //remove borders around the frame 
       setUndecorated(true); 
       //make the window fullscreen. 
       device.setFullScreenWindow(this); 
       //attempt to change the screen resolution. 
       device.setDisplayMode(dispMode); 
       setResizable(false); 
       setAlwaysOnTop(false); 
       //show the frame 
       setVisible(true); 
      } 
      //make sure that the screen is refreshed. 
      repaint(); 
     } 
    } 
 
+0

不错:)感谢很多朋友... – 2010-12-16 15:41:51

+0

这是一个非常广泛的应用程序全屏幕的方式。大多数其他指南只包括'device.setFullScreenWindow(this);'但这可能会留下不需要的边缘。我会亲自删除'setLocationRelativeTo(null);'虽然窗口似乎记得它的旧位置,并会返回到它。 – Finnboy11 2014-05-01 14:15:24