here is a solution for drawing whilst hiding the sketch window. This seems to create a new thread so I don’t know what limitations it may have.
import java.awt.Frame;
import processing.awt.PSurfaceAWT;
import processing.awt.PSurfaceAWT.SmoothCanvas;
PWindow win1,win2;
public void settings() {
size(1400, 700);
};
void setup() {
win1 = new PWindow(width/2-5,0,width/2,height,"first Window");
win2 = new PWindow(0,0,width/2,height,"Second Window");
surface.setLocation(-5, 0);
};
void draw() {
background(255, 0, 0);
fill(255);
rect(mouseX, mouseY, frameCount, 10);
if(win2.canvas!=null)image(win2.canvas,width/2,0);
if(win1.canvas!=null)image(win1.canvas,0,0);
};
void mousePressed() {
println("mousePressed in primary window");
};
class PWindow extends PApplet {
int x,y,w,h;
boolean setLocation,setTitle,makeResizable;
String title;
PImage canvas;
color bg = color(random(255),random(255),random(255));
PWindow() {
super();
PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
};
PWindow(int x_,int y_) {
super();
x = x_;
y = y_;
setLocation = true;
PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
};
PWindow(int x_,int y_,int ww, int hh) {
super();
x = x_;
y = y_;
w = ww;
h = hh;
setLocation = true;
PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
};
PWindow(int x_,int y_,int ww,int hh,String s) {
super();
x = x_;
y = y_;
w = ww;
h = hh;
setLocation = true;
title = s;
setTitle = true;
PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
};
PWindow(int x_,int y_, String s, boolean k) {
super();
x = x_;
y = y_;
setLocation = true;
title = s;
setTitle = true;
makeResizable = true;
PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
};
void settings() {
if(w>0&&h>0)size(w, h);
else size(500, 200);
};
void setup() {
background(150);
if(setLocation)surface.setLocation(x, y);
if(setTitle)surface.setTitle(title);
if(makeResizable)surface.setResizable(true);
surface.setVisible (false);
};
void draw() {
background(bg);
ellipse(random(width), random(height), random(50), random(50));
fill(255);
text(frameRate,20,20);
canvas = get();
};
void mousePressed() {
println("mousePressed in secondary window");
closeWindow();
};
void closeWindow(){
Frame frame = ( (SmoothCanvas) ((PSurfaceAWT)surface).getNative()).getFrame();
frame.dispose();
};
};
I’m dont know if there is a more efficient alternative to the canvas.get()
method.