I know this gets asked from time to time and I’ve gone through all the instructions I can find (this did work once upon a time but …)
Some background: I teach a high school CS2 course in object oriented design and we start out with Processing. At some point, BlueJ becomes a better environment for what I want to accomplish but I also want to leverage all the cool graphics we have done up to that point. So, we switch to BlueJ.
I know about importing the various Processing libraries and where to find them (I’m on OS X) and I know about extend PApplet and using settings() instead of just setup().
However when I have the following:
import processing.core.PApplet;
public class P3Test extends PApplet
{
public void settings() {
size(800, 600, P3D);
}
}
I still get the error telling me to put size() inside of settings. This happens immediately upon creating a P3Test object and invoking the settings() method as per typical BlueJ use. This is occurring based on the most recent BlueJ v5.0 and Processing 3.5.4.
If that is really happening it suggests there is a bug. As you may know the only way processing managed to keep size inside setup in a pde file, is to pre-process the pde file as in settings_demo.pde
I’m not too familiar with BlueJ but somehow you need the relevant jars on your classpath (possibly that’s what the libraries folder is for in settings?). I can auto-magically do this sort of thing with my ruby-processing projects, java is not as convenient.
In BlueJ you add the libraries rather then adding locations to a CLASSPATH (well, I’m sure it is just internally maintaining a CLASSPATH).
The issue I’m having does not seem to be in ability to find the libraries but the error seems to be internal to Processing.
The actual error text is (note, the error implies no problem finding the library):
When not using the PDE, size() can only be used inside settings().
Remove the size() method from setup(), and add the following:
public void settings() {
size(800, 600);
}
java.lang.IllegalStateException: size() cannot be used here, see size() \ Language (API) \ Processing 3+
at processing.core.PApplet.insideSettings(PApplet.java:949)
at processing.core.PApplet.size(PApplet.java:2018)
at P3Test.settings(P3Test.java:26)
I guess I need to try this in something like Eclipse and see if this is something strange in the interaction with BlueJ or something that has changed inside Processing.
In the source for PApplet.java there is a function insideSettings that checks if the use of size() was done inside an override of the settings() function when not using the PDE.
settings() is an empty public void that the user needs to override.
So far so good.
But how does the boolean insideSettings ever get set to true? It isn’t a public variable. It seems to be set to true by the function handleSettings() but that is also private. Basically it seems like the boolean intended to ensure a user is using settings() when external to the PDE is not, and can’t be, set too true.
At least, that’s my reading of the source.
Should the abstract version of settings() have
public void settings() {
insideSettings = true;
}
and then the proper use outside of the PDE would be to override settings:
public void settings() {
super.settings();
size(800, 600);
}
PcF
/**
param method “size” or “fullScreen”
param args parameters passed to the function so we can show the user
return true if safely inside the settings() method
*/
boolean insideSettings(String method, Object… args) {
if (insideSettings) {
return true;
}
final String url = “Language Reference (API) \ Processing 3+” + method + “_.html”;
if (!external) { // post a warning for users of Eclipse and other IDEs
StringList argList = new StringList(args);
System.err.println(“When not using the PDE, " + method + “() can only be used inside settings().”);
System.err.println(“Remove the " + method + “() method from setup(), and add the following:”);
System.err.println(“public void settings() {”);
System.err.println(” " + method + “(” + argList.join(”, “) + “);”);
System.err.println(”}");
}
throw new IllegalStateException(method + "() cannot be used here, see " + url);
}
Override this method to call size() when not using the PDE.
*/
public void settings() {
// is this necessary? (doesn’t appear to be, so removing)
//size(DEFAULT_WIDTH, DEFAULT_HEIGHT, JAVA2D);
}
Is it me or is that BlueJ is a bit cookie in that you need to click on the class diagram, then on the main method to get it to run? Also when I checked possibility of installing BlueJ 5.0 on the RaspberryPI that’s a no go, because of javafx requirement which is only available for 32 bit so I can’t install right version on ManjaroArm (64 bit), and BlueJ 5.0 is only available for 64 bit. I have zero interest in installing BlueJ on my linux box, where I use netbeans and atom to develop ruby-processing and processing projects.
Unlikely perhaps, but does changing "MySketch" to "P3Test" in processingArgs make any difference? Processing does expect that to be the class name.
Glad to see someone appreciates the IDE I put too much of my spare time into (looks at @paulgoux ! ) There was code to work directly with BlueJ projects inside NetBeans - looks like that might have gone astray in the Apache transition for now.
Monk, you don’t have to but that is the way one normally invokes methods. You can also simply invoke main() if you have one (which isn’t necessary). That’s actually the answer to paulgoux. I use BlueJ as a teaching environment to explore object oriented design process not as an efficient development environment to get to the end result. It serves a real purpose with high school students in making all the bits and pieces of OOP more concrete and less abstract, magical, incantations. It is particularly helpful with the whole coupling/cohesion topic and abstract classes and inheritance. I can also use the Greenfoot version to explore agent based modeling. It’s all part of a course sequence that uses Racket, Java, Python, Matlab and systems dynamics programming. There is a twisted logic. Twisted, but it’s there.
This did work with earlier versions of Processing/BlueJ so it is possible … must be doing something wrong (COVID threw all my courses off their stride and trying to get things back in sync is proving … difficult)
Thanks all.
PcF
p.s. Monk, I need to inspect handleSettings more carefully because I didn’t see how that was getting invoked. I did download the source free so I can try to understand how this is meant to work under the hood. That may take me a bit …
Just to close out this thread: after some months of frustration, using the libraries from the Processing 4 Beta did the trick. No fuss, no muss. All you need is add the core.jar, pde.jar and the various jog libraries from Processing to your BlueJ Prefs->Libraries
Use monkstone’s example static main above and be sure to use both a void settings() to hold size() and void setup as you normally would.