We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone,
This post is diverged from What is a natural learning path to create a processing library for a newbie?
After a nearly two days' torture in searching answers everywhere, I have just managed to run a processing code in Eclipse without error. The trick in my case seems to be:
must have the first line of code package NameOfPackage;
size()
must be inside settings()
;
must have main(String args[])
;
However, Why are all these? Where can I get to learn about all these requirements or tricks? Is there a way to link processing's documents or API to Eclipse for access?
Thanks!
package ImportProcessingCore;
import processing.core.*;
public class ProcessingTest extends PApplet {
public static void main(String args[]) {
PApplet.main(new String[] { ImportProcessingCore.ProcessingTest.class.getName() });
}
public void settings() {
size(600,600);
}
public void setup() {
background(0);
}
public void draw() {
fill(random(255),random(255),random(255),random(255));
rect(200,200,300,400);
}
}
Answers
package
. But it's important for library organization.Processing's own IDE (PDE) have some syntactic sugaries which must be converted to actual ".java" in order to be compiled.
You'll learn those tiny divergences faster if you export a sketch and study its ".java" output L-)
https://forum.Processing.org/two/discussions/tagged/eclipse
@GoToLoop Thanks, your suggestion of looking into export folder is very clever. However I can run processing code which only requires
import processing.core.*
, not processing code which require more to import. As I don't know where I can find .jar files for:Could you point out the places for those jar files above?
Thanks a lot
1) Java uses packages to organise classes. The package name has two features you should be aware of.
a) it represents the physiclal organisation on disk. So if you had a class called Foo and the package is called org.kenny then you would have a file called Foo.java in a folder called org/kenny i.e.
org/kenny/Foo.java
b) the other benefit of using packages is differentiate classes with the same name. For instance there are many classes called MouseEvent but inside the class the code is different. Here are 2 such classes
java.awt.event.MouseEvent
processing.event.MouseEvent
They are different classes each having their own java file. We can use the fully qualified class name as shown above to tell Java which one we want to use. A Processing sketch does not need to be in a package, you can save the class directly in the src folder. This is called the default package. If you are creating a library then the classes MUST be inside a package otherwise you can't
import
the classes.2)
settings
is required for Processing 3 and Eclipse, but not required in the Procesing IDE. Probably worth using it all the time in both.3)
main(String args[]);
is required in Java to say start here Processing has a pre processor that does this for you, but in Eclipse you have to add it yourself.Most of us who use Processing in Eclipse or created libraries have learned these things by trial and error. Even if you find a tutorial it is generally written by programmers who make assumptions about the readers skills, or say what you have to do not why
Fortunately there are people on this forum willing to help explain the why
@quark, thanks a lot! you have been very helpful!
Those imports above are basically the whole Processing's basic API.
They're automatically imported so it's ready to use in our ".pde" sketches.
Those 2 are the only Java containers that Processing "officially" supports.
Processing deals w/ IO too. In order for "artist" programmers to use those IO APIs, those imports are "necessary" to be transparently ready to use.
As you mighta guessed now, Processing API's "strategy" is have everything working right off the bat as long we stick to its "official" reference API: https://Processing.org/reference/
Of course if we're using another IDE, we should
import
only those libraries/classes we really need for the app to compile. Not everything plus the sink and the rest of the kitchen. 3:-OHi @GoToLoop, I tried your method and it is very clever. Thanks a lot!