We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProcessing DevelopmentLibraries,  Tool Development › Libraries for Dummies (Eclipse)
Page Index Toggle Pages: 1
Libraries for Dummies (Eclipse) (Read 2305 times)
Libraries for Dummies (Eclipse)
Jun 15th, 2006, 1:07pm
 
I've downloaded Eclipse and after a week of fustrating attempts I have completed my first Hello World program and run it successfully. I am all humility.

I've looked at the howto.txt and I'm afraid I don't understand how to implement the very basic library in Eclipse. I would like to build a Hello World library (i.e. I instance the library's class and run it's method which would println("Hello World"); to the console).

I appreciate I must come across as a chronic imbecile but although I will still try to figure this out on my own I'm having real trouble here. (I've finished my degree by the way, this is so I can build an A.I. library for Processing, it's not homework.)
Code:

package libraryexample;
import processing.core.*;

public class BoringLibrary {
PApplet parent;

public BoringLibrary(PApplet parent) {
this.parent = parent;
parent.registerDispose(this);
}

public void dispose() {
// anything in here will be called automatically when
// the parent applet shuts down. for instance, this might
// shut down a thread used by this library.
// note that this currently has issues, see bug #183
// http://dev.processing.org/bugs/show_bug.cgi?id=183
}
}

My concern is that I don't understand how Eclipse is going to find processing.core.*. I don't even know how to compile in Eclipse yet. Any help would be very much appreciated.
Re: Libraries for Dummies (Eclipse)
Reply #1 - Jun 15th, 2006, 5:55pm
 
So I created a Java Project called HelloClass. It gave me the JRE System Library in there. Don't know what that's for. I created Hello.java:
Code:

package HelloLibrary;
import processing.core.*;

public class Hello {
PApplet parent;
public Hello(PApplet parent) {
this.parent = parent;
parent.registerDispose(this);
}
public void helloWorld(){
println("Hello World");
line(0, 0, 100, 100);
}
public void dispose() {
}
}

I got an error line under the import command so I created a new source folder called "processing" and copied core.jar into it. I exported the project as a .jar file into the code folder of a sketch:
Code:

Hello hello;

void setup(){
hello = new Hello(this);
hello.helloWorld();
}

I got a no Hello found. I looked at someone else's library (just the Ess one for a quick check) and noticed no core.jar in there. So I deleted the processing source folder and tried exporting again and testing again. No Hello found.

I tried HelloLibrary hello; as the first line and got:
Code:

C:/DOCUME~1/Aaron/LOCALS~1/Temp/build41520.tmp/Temporary_3653_2276.java:1:269:1:280: Semantic Error: Found package ".HelloLibrary" when a type was expected.

So it can see the .jar file okay. I still haven't got a bloody clue what I'm supposed to do yet. Any pointers?
Re: Libraries for Dummies (Eclipse)
Reply #2 - Jun 15th, 2006, 9:26pm
 
Okay. Let's see if I can help. I was pretty confused with Eclipse but I got it to work just by trial and error.

To get the processing.core import to work, right click on your project and go to properties, and then in the box that pops up go to "Java Build Path" and then to the Libraries tab. Click "Add External Jars". Now you just have to find the core.jar and add it.

Then I think to get the package, you just right click on the project and go to new>package and fill in the name. After that you can do the same thing to make a new class for the package and then just write your code in that.

Okay now for the export.. I'm pretty sure Eclipse compiles on the fly so there's no need to do that yourself. To export the jar file for a library, just right click on the package you made, and export. Then choose JAR file, and it will have a place you can put the pathname where you want it exported. I usually have it export right into it's folder in the P5 libraries folder so I can work back and forth easily.

Anyway I hope that helps make Eclipse less cryptic.

ryan
Re: Libraries for Dummies (Eclipse)
Reply #3 - Jun 16th, 2006, 12:53pm
 
Thanks a lot for that. I followed your instructions - I had previously made a class outside of a package and I hadn't set up the build path. I've managed to make my first helloLibrary package.

Eclipse:
Code:

package helloLibrary;
import processing.core.*;

public class Hello{
PApplet parent;
public int myInt = 0;
public Hello(PApplet parent){
this.parent = parent;
parent.registerDispose(this);
}
public void helloWorld(){
myInt++;
parent.println("Hello World");
parent.line(0, 0, 100, 100);
}
public void dispose(){
}
}

Processing:
Code:

Hello hello;

void setup(){
hello = new Hello(this);
println(hello.myInt);
hello.helloWorld();
println(hello.myInt);
}

So I'm cool for now, thanks. I think that for the AI library most of the stuff that happens is going to be internal math, I'll just need some tips on how to keep what is going on in the library quiet from the user.

One question though:

I get a warning from Eclipse on

parent.println("Hello World");

The static method println(String) from the type PApplet should be accessed in a
static way

It says it compiles with errors but runs anyway. Is there a better way I should be calling println()? Or should I just ignore it.
Re: Libraries for Dummies (Eclipse)
Reply #4 - Jun 16th, 2006, 9:09pm
 
Oh yeah. the fact that a lot of methods in the core are static is actually really helpful. You just access it like this:

PApplet.println();

So.. you don't need an instance of PApplet at all if all you are doing is accessing static methods.
Re: Libraries for Dummies (Eclipse)
Reply #5 - Aug 18th, 2006, 9:29pm
 
Hi,
i am also using Eclipse to write my own Library and want to test directly from Eclipse and get a NullPointerException on an simple try. here is the code:

import processing.core.*;

public class ToolKit {

public ToolKit() {
super();
}

public static void main(String[] args) {
System.out.println("blub");
PApplet p = new PApplet();
p.size(200,200);
}
}

the Exception is caused by the line p.size(200,200); how can i fix it. or isn't possible to write p5 programs in Java?
Re: Libraries for Dummies (Eclipse)
Reply #6 - Oct 29th, 2006, 3:22pm
 
RE: ramin's bit.

P5 is Java. size() is a magickal function to be called at the beginning of setup() and nowhere else - not inside a library. That's just trying to break things.

My Question

I'd like the format of my library to take the same tack as traer.physics. As in:
Code:

// importing GeneticAlgorithm
import ai.ga.*;

// importing AStar
import ai.astar.*;

// importing BPN (Back Propagation Network)
import ai.bpn.*;

I only set it up as gaLibrary and such because I didn't know how to get that family.library.* format.

I'd like to change this as soon as possible. How do I set up Eclipse to do this?

(Bear in mind I'm not importing PApplet into any of the A.I. family, I just set things up to output floats, if that makes any difference.)
Re: Libraries for Dummies (Eclipse)
Reply #7 - Oct 29th, 2006, 4:07pm
 
re: p5 programs in java, see the developer reference for PApplet:
http://dev.processing.org/reference/core/javadoc/processing/core/PApplet.html
Re: Libraries for Dummies (Eclipse)
Reply #8 - Oct 29th, 2006, 5:50pm
 
re: Aaron is a booger.

You just have to rename the package and stick in as many stops as you like.

ie:

package ai.ga;

I will update the documentation and libraries soon - but I intend to do a build of ai.ga using the mersene twister library. GA's use a lot of random numbers - I think the option of better random numbers would be good.
Page Index Toggle Pages: 1