How to write and run processing code in Eclipse? How to make Eclipse a second home for processing?

edited November 2015 in How To...

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:

  1. must have the first line of code package NameOfPackage;

  2. size() must be inside settings();

  3. 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

  • edited November 2015 Answer ✓
    1. AFAIK, we're not obliged to use keyword package. But it's important for library organization.
    2. size() & smooth() inside settings() is Processing 3's exclusive new demand.
    3. All Java code needs to have 1 of those main() as a starting execution point. ;))

    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:

    import processing.data.*; 
    import processing.event.*; 
    import processing.opengl.*; 
    
    import java.util.HashMap; 
    import java.util.ArrayList; 
    import java.io.File; 
    import java.io.BufferedReader; 
    import java.io.PrintWriter; 
    import java.io.InputStream; 
    import java.io.OutputStream; 
    import java.io.IOException; 
    

    Could you point out the places for those jar files above?

    Thanks a lot

  • Answer ✓

    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.

    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?

    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!

  • edited November 2015 Answer ✓

    import processing.core.*;
    import processing.data.*;
    import processing.event.*;
    import processing.opengl.*;
    

    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.


    import java.util.HashMap;
    import java.util.ArrayList;
    

    Those 2 are the only Java containers that Processing "officially" supports.


    import java.io.File; 
    import java.io.BufferedReader; 
    import java.io.PrintWriter; 
    import java.io.InputStream; 
    import java.io.OutputStream; 
    import java.io.IOException; 
    

    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:-O


  • Hi @GoToLoop, I tried your method and it is very clever. Thanks a lot!

Sign In or Register to comment.