I don't understand how I can switch applets in the same window. I want to switch to an applet that plays a video file after I click a button on a button menu. On the video applet, I want a two buttons that asks the user to replay or go back to the button menu. So basically, a menu system that displays video and then replays the video or goes back to the menu if the user chooses. I've seen the two applet hack here on the threads, but that opens up a new window instead of using the current window (having the user open too many windows is bad).
In terms of code, I have two applets. One that has the buttons, and one that plays videos (taken from the examples).
Code:
// The Menu with the buttons
import controlP5.*;
ControlP5 controlP5;
void setup(){
size(500,500);
smooth();
controlP5 = new ControlP5(this);
controlP5.addButton("trainOne", 0,100,100,48,20);
controlP5.addButton("trainTwo", 0,200,200, 30, 20);
controlP5.addButton("trainThree", 0, 150,150, 20, 20);
}
void draw() {
background(0);
}
public void controlEvent(ControlEvent e) {
println(e.controller().name());
}
public void trainOne(int v) {
println("This should play train.mov");
}
public void trainTwo(int v) {
println("This should play train2.mov");
}
public void trainThree(int v) {
println("This should play train3.mov");
}
Code:
// Taken from the examples with slight modifications. Plays the movie train.mov. For now, just assume train.mov, train2.mov, and train3.mov are the same video file.
import processing.video.*;
import controlP5.*;
Movie myMovie;
ControlP5 controlP5;
void setup() {
size(640, 480, P2D);
background(0);
controlP5 = new ControlP5(this);
controlP5.addButton("Return to menu", 0,100,100,48,20);
controlP5.addButton("Replay", 0,100,100,48,20);
// Load and play the video in a loop
myMovie = new Movie(this, "train.mov");
myMovie.loop();
}
void movieEvent(Movie myMovie) {
myMovie.read();
}
public void controlEvent(ControlEvent e) {
println(e.controller().name());
}
public void Replay(int v) {
println("Assume this replays");
}
public void ReturnToMenu(int v) {
println("How to do this back to menu?");
}
void draw() {
tint(255, 20);
image(myMovie, mouseX-myMovie.width/2, mouseY-myMovie.height/2);
}
How do I tie these two together into the same window?