We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I know how to build a second window, how to build button with his own draw() … But how to do all in the same sketch ? Here is my code :
import java.awt.*;
PFrame f;
AutreApplet s;
void setup() {
size(200, 200);
s = new AutreApplet();
f = new PFrame(s);
}
void draw() {
background(255, 0, 0);
}
public class PFrame extends Frame {
public PFrame(AutreApplet autre) {
setBounds(100, 100, 200, 200);
add(autre);
autre.init();
setVisible(true);
}
}
public class AutreApplet extends PApplet {
boolean temoin;
Bouton b;
void setup() {
size(200, 200);
b = new Bouton(this, 100, 100);
}
void draw() {
background(0);
}
}
public class Bouton {
PApplet parent;
PVector position;
Bouton (PApplet _parent, int _x, int _y) {
parent = _parent;
position = new PVector(_x, _y);
parent.registerMethod("draw", this);
}
void draw() {
fill(255);
rect(position.x, position.y, 40, 40);
}
}
It seems to be a PApplet problem. The white rectangle appears sometime int the main red window. If you have got an idea to solve my problem it will be great.
Best regards.
Answers
Not exactly a solution, but a better way to get PApplet multi-instances: =:)
http://forum.processing.org/two/discussion/7202/controlp5-controlwindow-and-controlp5frame
You do a great job, but I understood that my problem is the nested class. I will search some explanations later on the web cause my code works : import java.awt.*;
Well, in my style we don't need to create a Frame. ;;)
Anyways, no need to pass the AutreApplet's reference to Bouton. After all, Bouton is a nested inner class of it!