We are about to switch to a new forum software. Until then we have removed the registration on this forum.
till processing 3 i have often made that successfully. Yesterday, answering to some question that you can see here forum.processing.org/two/discussion/12624/can-i-launch-an-instance-of-processing-inside-of-a-control-on-a-sketch#latest i posted the code you can see at the same url. This code works, i have used it many times and tested the snippet i put. Yet theOP said me "this code does not work, it fires that the applet.init() method does not exist" and he added that he was using processing 3. So, i went to the docs / changes && found that:
"As of Processing 3.0, we have removed Applet as the base class for PApplet. This means that we can remove lots of legacy code, however one downside is that it's no longer possible (without extra code) to embed a PApplet into another Java application"
ok. But i would be very happy to understand by an example what kind of "extra code" i could use... thanks in advance
Answers
http://forum.Processing.org/two/discussions/tagged?Tag=papplet.runsketch()
@GoToLoop== thanks, i have not read these posts, very interesting, before; but if i resume solution is to look at runsKetch() method???
Functions main() & runSketch() always existed in Processing. At least since v1.5.1.
The Frame class approach was never necessary in most cases and shouldn't even be presented as 1st option for folks looking for multiple windows.
@GoToLoop== i knew for main(), but never saw nor used runSketch()...Now, for better understanding, i have to work with your code... i am somewhat puzzled by PS3 by settings() vs setup() and so on and finally by the exact "lifeCycle" of a processing sketch... thanks
@GoToLoop==
ok, i have given a look to the code && i understand better; as for settings() i have found the infos and it's ok, it could be useful. As for the way to create your second window through this mysterious runsKetch() method (found nothing about it till now) and a class extending PApplet, i have some questions:
--- in the runSketch() method you pass a String[] as argument, but what can you put in this one??? - I see display, i see location but what can i add??? - iHave tried with "--background() commenting your random() but it does nothing...
--- as for a JFrame you can easily set it to undecorated or... and also set the way it interacts with user (resizable...NOTHING.ON.CLOSE...and so on). Is it possible to do the same with your projector ??? - In the code i have posted (which does not run in PS3 of course) if the user closes 1 window, the sketch continues; with your code if he does the same the twos windows are closed && the sketch stops running...
When using runSketch(), those arguments are totally optional.
We can simply pass some String[] w/ only an empty
""
element in it.Just make sure it has at least some invalid/unrecognizable argument in it though. @-)
""
is invalid btW. ;;)We don't have control of what is actually created inside runSketch(). :(
Most we can do is pass those String[] arguments. Sorry... 8-|
@GoToLoop== - bad news for the first question (yet i have seen that you can set the location with these args && i dont understand why you cannot set background...or more) - but for the second one??? Bad news also??? but many thanks because without your answer i probably loose 12 hours for nothing!
Even though we don't have control over runSketch(), default renderer JAVA2D is still based on JFrame.
In this forum thread below there's an example that use
(PSurfaceAWT)
over variable surface.Then calls getFrame() in order to get the "real" renderer of it:
http://forum.Processing.org/two/discussion/12260/processing-3-init-disappearance
Who knows,
((PSurfaceAWT)getSurface()).getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
might work! [-O<@GoToLoop:: i'll see that!!! - But let me say that what you said before "The Frame class approach was never necessary in most cases and shouldn't even be presented as 1st option for folks looking for multiple windows." == true, it is (it was) because P5 (&&G4P lib!) could solve easily the problem. As for me, now, if i have a problem of this kind i leave processing and go to java::: more simple!
Here's what I've come up with: :>
I believe that excerpt can be used for PApplet instances created outta runSketch() too.
THANKS: that is answering! ( though i always was told to NOT mix AWT && Swing...)
According to setDefaultCloseOperation() method:
http://docs.Oracle.com/javase/8/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation-int-
We've got 4 constants to choose from:
Dunno which 1 you're looking for though. You gotta check it out for yourself! :-h
@GoToLoop:: "I believe that excerpt can be used for PApplet instances created outta runSketch() too." i ll try tomorow and tell you ^:)^
Swing package depends on AWT package! :-B
@goToLoop:: i know, i have choosen DO_NOTHING_ON_CLOSE because i have add my own windowListener overriding the closeWindow:: not any problem with that!
@ goToLoop:: according to oracle:
@ goToLoop== but that is another problem!!!! :))
There's nothing getting mixed up! JFrame class is Swing.
And in turn, JFrame directly extends Frame, which is AWT:
@GoToLoop: right, in THIS case... and... but i am tired out!
@GoToLoop::
Not Found
The requested URL /reference/javadoc/core/processing/awt/PSurfaceAWT.html was not found on this server.
????
https://GitHub.com/processing/processing/blob/master/core/src/processing/awt/PSurfaceAWT.java
https://Processing.org/reference/javadoc/everything/processing/core/PSurface.html
Hi, how to do the same with FX2D? I cannot figure out how to retrieve the Stage of the PApplet...? Thanks.
Dunno. But you're gonna need to chase the trail:
https://GitHub.com/processing/processing/blob/master/core/src/processing/javafx/PGraphicsFX2D.java
Very l8 but here's how to get FX2D's Stage:
https://forum.Processing.org/two/discussion/17675/how-to-get-surface-window-x-and-y-coordinates#Item_12
And Stage's API: http://docs.Oracle.com/javase/8/javafx/api/javafx/stage/Stage.html