Java 2.0 processing (using Eclipse): moving from window to fullscreen and vice versa

I use Processing 2.0 in Eclipse and ask a question about the transition between windowed mode and fullscreen screen for a running application (without choosing windowed or fullscreen mode at startup, which is easily solved).

This question solves the problem of switching from full-screen mode in Java Processing to windowed mode.

However, I would also like to know how to switch from window mode back to full screen mode using Processing. Anyone have a solution to this problem?

+3
source share
1 answer

A bit hacky, but you can try creating a separate AWT frame, which is full-screen, and drop the handler into it. Usually for full-screen viewing you only need a frame with the size of the screen and without decorations (title bar, close buttons, etc.). The trick is you cannot "decompose" java.awt.Frame after it has been set to visible (even if you set the visibility to false, try to decompose, and then create the frame again), so bypassing this will just be a separate instance of Frame, already not decorated and with the correct dimensions, to which we discard the contents of the frame. We also need to inform that the evaluation processing is being updated.

Here is a quick sketch illustrating the idea (press "f" for full screen mode):

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 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 frame fullScreenFrame.setVisible(true);//make our fullscreen frame visible frame.setVisible(false );//and hide Processing frame } } 
+1
source

Source: https://habr.com/ru/post/1236524/


All Articles