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

后端 未结 1 336
一个人的身影
一个人的身影 2021-01-14 13:57

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 f

相关标签:
1条回答
  • 2021-01-14 14:52

    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
       }
    } 
    
    0 讨论(0)
提交回复
热议问题