When searching the forum I found the following code (posted by smallfry back in 2007)
It creates a second PApplet window (inside a Java Frame).
When I close either window it closes both, what I want to be able to do is close the second window leaving the initial window open.
Removing the System.exit(0) simply prevents the second window from closing!
Any ideas welcome?
Code:
private static secondCanvas sCanvas;
private static secondApplet sApplet;
import java.awt.*;
import java.awt.event.*;
import processing.core.*;
int xPos = 0;
int yPos = 0;
void setup() {
size(400, 400);
smooth();
background(0);
noStroke();
sApplet = new secondApplet();
sCanvas = new secondCanvas("follower", sApplet, screen.width/2, screen.height/2);
}
void draw() {
background(0);
fill(200, 100, 0);
rect(xPos++,0, 100, 100);
if(xPos >= width) xPos = 0;
}
public class secondApplet extends PApplet {
public void setup() {
size(400, 400);
background(255, 0, 0);
frameRate(10);
}
public void draw() {
background(0);
fill(200, 100, 0);
rect(0, yPos++, 100, 100);
if(yPos >= height) yPos = 0;
}
}
public class secondCanvas extends Frame {
public secondCanvas(String name, PApplet embed, int x, int y) {
super(name);
// add the PApplet to the Frame
setLayout(new BorderLayout());
add(embed, BorderLayout.CENTER);
// ensures that the animation thread is started and
// that other internal variables are properly set.
embed.init();
// add an exit on close listener
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
// exit the application
System.exit(0);
}
});
setSize(400, 400);
setLocation(x, y);
setVisible(true);
}
}