Java Processing 2.0 (Using Eclipse) : Switching from window to fullscreen and back

若如初见. 提交于 2019-12-01 06:19:08

问题


I am using Processing 2.0 in Eclipse and have a question regarding the transition between windowed mode and fullscreen for a running application (not selecting windowed or fullscreen at startup, which is easily solved).

This question solves the problem of going from the fullscreen mode in Java Processing to windowed mode.

However, I would also like to know how to transition from windowed mode back to fullscreen using Processing. Does anyone have a solution to this problem?


回答1:


A bit hacky, but you can try creating a separate AWT Frame which is fullscreen and drop Processing's applet into it. Normally for fullscreen you should only need a frame with the screen dimensions and no decorations (title bar, close buttons, etc.) The catch is you can't 'undecorate' a java.awt.Frame after it's been set to visible (even if you set visibility to false, attempt to undecorate, then make the frame visible again), so to go around this will simply have a separate Frame instance, already undecorated and with the right dimensions into which we drop Processing's frame content. Also we need to tell processing the bounds are updated.

Here's a quick sketch to illustrate the idea(press 'f' for fullscreen):

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
   }
} 


来源:https://stackoverflow.com/questions/23260640/java-processing-2-0-using-eclipse-switching-from-window-to-fullscreen-and-ba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!