Skip to content

Instantly share code, notes, and snippets.

@atduskgreg
Last active November 21, 2015 19:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atduskgreg/ad689ff9685345ae6cee to your computer and use it in GitHub Desktop.
Save atduskgreg/ad689ff9685345ae6cee to your computer and use it in GitHub Desktop.
Example of creating a Processing sketch with multiple windows. NOTE: this doesn't work in Processing 3.0. See the Processing 3.0 version here: https://gist.github.com/atduskgreg/666e46c8408e2a33b09a
import java.awt.Frame;
PWindow w;
void setup() {
size(320, 240);
w = new PWindow(100, 100, 500, 200);
}
void draw() {
background(255, 0, 0);
fill(255);
rect(10, 10, frameCount, 10);
w.app.background(0, 0, 255);
w.app.fill(100);
w.app.rect(10, 20, frameCount, 10);
w.app.redraw();
}
void mousePressed(){
println("mousePressed");
}
class PWindow extends Frame {
PWindowApp app;
PWindow(int x, int y, int w, int h) {
setBounds(x,y,w,h);
app = new PWindowApp();
app.setParent(this);
add(app);
app.init();
show();
}
}
class PWindowApp extends PApplet {
Frame parent;
void setParent(Frame _parent){
parent = _parent;
}
void setup() {
size(parent.getWidth(), parent.getHeight());
noLoop();
}
void draw() {
}
// all mouse, keyboard events work in here as expected
// TODO: Could there be an API for defining these from the outside?
void mousePressed(){
println("second app mouse pressed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment