Java Processing 2.0(使用Eclipse):从窗口切换到全屏模式再返回

3

我正在Eclipse中使用Processing 2.0,关于运行应用程序时从窗口模式到全屏模式的转换有一个问题(不是在启动时选择窗口模式或全屏模式,这很容易解决)。

这个问题解决了从Java Processing的全屏模式转换为窗口模式的问题。

然而,我也想知道如何使用Processing从窗口模式转换回全屏模式。有人有这个问题的解决方案吗?

1个回答

1
有点小技巧,但您可以尝试创建一个全屏的独立AWT Frame,并将Processing的applet放入其中。通常情况下,全屏只需要一个具有屏幕尺寸和没有装饰(标题栏,关闭按钮等)的框架即可。问题是,在java.awt.Frame设置为可见后,您无法“去除”它的装饰(即使您将可见性设置为false,尝试去除装饰,然后再次使框架可见),因此我们将简单地拥有一个单独的Frame实例,已经去除了装饰并具有正确的尺寸,我们将Processing的框架内容放入其中。另外,我们需要告诉processing更新边界。
这里是一个快速草图,以说明这个想法(按“f”键进入全屏模式):
import java.awt.Frame;
Frame fullScreenFrame;
void setup(){
  fullScreenFrame = new  Frame();
  fullScreenFrame.setUndecorated(true);//prepare an undecorated fullscreen frame since java won't allow you to 'undecorate' a frame after it's been set visible 
  fullScreenFrame.setBounds(0,0,displayWidth,displayHeight);
  fullScreenFrame.addKeyListener(getKeyListeners()[0]);//pass key events from this applet to the fullScreen Frame
}
void draw(){
  background((float)mouseX/width * 255,(float)mouseY/height * 255,0);
}
void keyReleased(){
  if(key == 'f') {
      setBounds(0,0,displayWidth,displayHeight);//resize the skech
      fullScreenFrame.add(frame.getComponent(0));//add the applet to the fullscreen frame from Processing's frame
      fullScreenFrame.setVisible(true);//make our fullscreen frame visible
      frame.setVisible(false );//and hide Processing's frame
   }
} 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接