We are about to switch to a new forum software. Until then we have removed the registration on this forum.
This is a followup to my Frame=Null frame.setState(...) issue answered in http://forum.processing.org/two/discussion/5836/eclipse-papplet-frame-setstateiconified-not-working-as-frame-null#Item_5
Here is the Eclipse code for creating 2 frames. Both will by Iconified with a mouseclick.
import java.awt.Frame;
import processing.core.PApplet;
public class Part1 extends PApplet
{
SecondFrame frame2;
public static void main(String args[])
{
PApplet.main(new String[]
{"Part1" });
}
public void setup()
{
size(300, 500);
frame2 = new SecondFrame(550,250,500,300,"Second Frame");
}
public void draw()
{
background(125);
text("Hello World!", 30, 30);
}
public void mousePressed()
{
frame.setState(Frame.ICONIFIED);
}
}
with the added class
import java.awt.Frame;
import java.awt.BorderLayout;
import processing.core.*;
public class SecondFrame extends java.awt.Frame
{
int xLoc;
int yLoc;
int h;
int w;
String name;
SecondApplet frame2;
SecondFrame( int x_, int y_, int w_, int h_, String name_)
{
super("Embedded PApplet");
xLoc = x_;
yLoc = y_;
w = w_;
h = h_;
name = name_;
frame2 = new SecondApplet();
add(frame2, BorderLayout.CENTER);
frame2.init();
setBounds(xLoc, yLoc, w, h);
setTitle(name);
setVisible(true);
}
public class SecondApplet extends PApplet
{
public void setup()
{
background(175);
size(500, 300);
}
public void draw()
{
background(225);
text("Hello Universe!", 60, 40);
}
public void mousePressed()
{
setState(Frame.ICONIFIED);
}
}
}
Answers
I couldn't find your question or request anywhere!
Nonetheless, the link below got some examples about multi PApplet instantiations:
http://forum.processing.org/two/discussion/4140/use-displayn-command
Thanks for the pointer.
That reference shows how to have multiple PApplet instances that share the same setup() and draw() code. Cool idea. (Granted the logic applied to each frame can be controlled by if (Id == suchandsuch) ... references.)
I was looking for an approach and permits interactive window creation, where each frame is its own PApplet with its own setup() and draw().
Two different multiple window approaches, each having its place.
One approach is multiple instances of the same PApplet sharing logic, the other separate instances of different PApplets each with its own logic.
Note an array of SecondFrame secondFrames[]; could accomplish your referenced approach, but would no longer share the logic but have separate copies of the logic. This would use more memory and more cpu I would think.
Further investigation's confirmed that PApplet.main() can instantiate any top class (".java") as long as it
extends
PApplet. :-bdIn my huge example below, I've got 3 separate apps united as 1 executable, but w/ their own canvas. Check it out: :bz
"Multiple_PApplet_Instantiations.pde":
"RotatingCard.java":
"RotatingCars.java":
"SquareFlower.java":