We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello Processing community!
I am having the following problem:
I have a program that at some point creates a second window.
In that second window I have the usual setup() and draw(), and here's what's funny:
When I include a function that does some drawing (for example a rectangle) in the second window's draw(), that rectangle appears in the main window. Yet when I try rect() straight into the second window draw() it plots in the second window as expected.
Here's some code to illustrate:
DOESN'T WORK:
import javax.swing.JFrame;
PFrame statsWindow;
secondWindow s;
public class secondWindow extends PApplet {
public void setup() {
background(255);
}
void draw() {
plotter();
}
}
void plotter() {
fill(0);
rect(10,10,100,100);
}
public class PFrame extends JFrame {
public PFrame() {
setBounds(100, 100, 220, 220);
s = new secondWindow();
add(s);
s.init();
setDefaultCloseOperation(HIDE_ON_CLOSE);
}
}
WORKS (plots in the second window):
public class secondWindow extends PApplet {
public void setup() {
background(255);
}
void draw() {
fill(0);
rect(10,10,100,100);
}
}
(duplicate code omitted)
Any ideas why the first code doesn't plot on the second window? How do I do this properly using an auxiliary function? (I don't want to put all my code inside the draw() function)
Regards,
Alex
Comments
Running the code you posted only displays a single window for me, and none of your code is triggered. Can you post your code as an MCVE that actually shows two windows?
Hi @KevinWorkman
Sorry, I should have been more clear. I can't post my entire program as it is too big, but here's a little example that illustrates the problem:
Hope that helps you understand what I'm trying to say.
Regards, Alex
Try moving the plotter method indide the SecondWindow class
BTW by conventil the name of a class starts with an uppercase letter.
Alternatively you could use the G4P library as it has good support fror multple windows. ;)
Hi @quark
I know this, thank you. The whole deal for me was to have the class that controls the second window in a separate file, trying to make it as less messy as possible, but I guess I'll have to do with having it inside the same class.
Thank you all.
EDIT: Forgot answering about G4P, thanks. I have been avoiding using external libraries, but I might give it a try too.
@alejoar::
or like this??? (it seems more clear for me without "plotter()", but!)
Thank you @akenaton
Although your example is exactly what @quark suggested (moving the method into the second window class) I appreciate your answer.
thanks! -- i have tried to make classes independant, as you ask for...
You might try this.
@quark you just nailed it!
Thank you very much!