In fact, there are quite a few implementation questions. Do you want just one big application or do you also want them to be different? Do you want to run three ready-made applications or want to combine the source code? You can also add them to libraries ... As for your comment in another question ( Create several windows of one sketch in the Processing section ), yes, of course, you can create another PApplet to store your application. I slightly modified the demo example.
Here I created two sketches of RedBG and BlueBG as follows:
int counter = 0; public void setup() { size(400, 400); counter = 0; } public void draw() { background(255, counter, counter); fill(255-counter); text(String.valueOf(counter), width*0.5, height*0.5, width, height); counter++; }
This red, blue has background(counter, counter, 255); , and both of them work as correct sketches. Then I took two codes and placed them on different tabs in the sketch of the controller and wrapped them in classes as follows:
public class RedBG extends PApplet { int counter = 0; public void setup() { size(400, 400); counter = 0; } public void draw() { background(255, counter, counter); fill(255-counter); text(String.valueOf(counter), width*0.5, height*0.5, width, height); counter++; } }
Then the controller class is just a modification of my answer in here . Here is his code:
import javax.swing.*; PApplet r, b; PFrame rf, bf; String nextWindow = "red"; int controllerCounter = 200; String control = "preparing..."; void setup() { size(400, 400); r = new RedBG(); b = new BlueBG(); frame.setTitle("controller"); fill(0); } void draw() { background(255); if (controllerCounter < 1) { switchState(); controllerCounter = 200; } control = null; control = "Launching " + nextWindow + " in: " + controllerCounter; text(control, width*0.5, height*0.5, width, height); controllerCounter--; } void switchState() { if (nextWindow == null) { stopApplet(b); nextWindow = "red"; } else if (nextWindow.equals("red")) { startApplet(r); nextWindow = "blue"; } else if (nextWindow.equals("blue")) { stopApplet(r); startApplet(b); nextWindow = null; } } void startApplet(final PApplet p) { if (p == null) return; final PFrame f = new PFrame(p); p.frame = f; f.setTitle(p.getClass() + " window");
Two classes that came from the sketches:
public class BlueBG extends PApplet { int counter = 0; public void setup() { size(400, 400); counter = 0; } public void draw() { background(counter, counter, 255); fill(255-counter); text(String.valueOf(counter), width*0.5, height*0.5, width, height); counter++; } }
and
public class RedBG extends PApplet { int counter = 0; public void setup() { size(400, 400); counter = 0; } public void draw() { background(255, counter, counter); fill(255-counter); text(String.valueOf(counter), width*0.5, height*0.5, width, height); counter++; } }
In short, take all of your code from three thumbnails (all tabs), drop them into a new tab in the thumbnail of the controller and wrap it with a class extending PApplet.
Unfortunately, you cannot have the tabs of your three thumbnails in the thumbnail of the controller unless you change your code. In the modified example below, only lala1 () and lala3 () are displayed in the blue window. lala2 () is in the controller window ...
public class BlueBG extends PApplet { int counter = 0; public void setup() { size(400, 400); counter = 0; } public void draw() { background(counter, counter, 255); fill(255-counter); text(String.valueOf(counter), width*0.5, height*0.5, width, height); counter++; lala1(); lala2(); lala3(this); } public void lala1() { fill(255, 255, 0); ellipse(100, 100, 100, 100); } } public void lala2() { fill(255, 0, 255); ellipse(150, 150, 100, 100); } public void lala3(PApplet p) { p.fill(0, 255, 255); p.ellipse(200, 200, 100, 100); }
And last but not least, sometimes the code will throw a NullPointerException and strange error messages, such as "the absence of pushMatrix () to jump with popMatrix ()" when calling the background method. This is caused by the call to setup() in the startApplet() method, and this is a concurrency problem, so it requires deeper thinking and knowledge ... As a temporary measure, I made it call setup() from the thread ... If you are not going to repeat the process, then the whole thread is not needed, and you do not need to setup() every time.!
PS This is a hack slash solution ... My suggestion is to combine your thumbnails into one and do it right ...