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.
IndexProgramming Questions & HelpIntegration › How to write and import own Java Classes
Page Index Toggle Pages: 1
How to write and import own Java Classes? (Read 2538 times)
How to write and import own Java Classes?
Feb 17th, 2009, 6:16pm
 
I just don't know how to create a java class and import it to processing. I'm using Processing 1.0 on a winXP, Java 6 Update 10, using BlueJ for native Java.

So how does it work?

I wrote a simple class "Point2D" in BlueJ and compiled it:

Code:

class Point2D
{
 float x=0;
 float y=0;
 
 Point2D(){}
 
 Point2D(float x, float y)
 {
  this.x=x;
  this.y=y;
 }
 
}

So I got the "Point2D.class"-file and copied it to the sketchfolder and then i tried to import it writing

import Point2D;

I tried to use Point2D.java and Point2D.jar files and put them also in a subfolder "libraries" with no luck.

So what's the problem? I have to many guesses so thats why I'm asking. I'm almost going crazy because I just can't solve this problem.



Re: How to write and import own Java Classes?
Reply #1 - Feb 17th, 2009, 7:04pm
 
Side note: Processing's PVector is equivalent to your class...

Anyway, that's not the point.
To use a Java class in a Processing sketch, you just need to put the .java file (not the .class) in the folder where you have the sketch that will use the class.
The Java class will appear as an additional tab in the PDE.
Re: How to write and import own Java Classes?
Reply #2 - Feb 17th, 2009, 8:01pm
 
Thank you very much! Saved my day...


Side note:
This was an exmaple snippet my Point2D class is older than PVector and has a lot of more features Smiley
Re: How to write and import own Java Classes?
Reply #3 - Feb 20th, 2009, 12:59pm
 
You can use compiled .class files, but that have to go in a "code" subfolder of your sketch directory.
Page Index Toggle Pages: 1