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 › multiple classes/files in Eclipse
Page Index Toggle Pages: 1
multiple classes/files in Eclipse (Read 639 times)
multiple classes/files in Eclipse
Aug 20th, 2008, 1:02pm
 
Hey everyone

I have downloaded Eclipse and have the HelloP5 tutorial working. Now i am trying to get multiple files working.

I have two classes, both in there own files.

procesingTest which extends PApplet and is the same as the tutorial.

import processing.core.*;

public class processingTest extends PApplet {


public void setup() {


   size(200, 200);


   stroke(155, 0, 0);


   PrintHelloWorld testPrint = new PrintHelloWorld();
   print("Hello World"); // This works
   System.out.println("Hello World 2"); // This works

}


public void draw() {
   line(mouseX, mouseY, width/2, height/2);

}

}


And i have PrintHelloWorld

import processing.core.*;

public class PrintHelloWorld {

public void main() {


   // print("Hello World"); THIS DOESNT WORK


   System.out.println("Hello World 2"); // This doesn't appear but compiles

}

}

Now the lines

print("Hello World");
System.out.println("Hello World 2");  
   
works in processingTest but fails in the PrintHelloWorld class. The processing function print() doesn't work i could kinda understand but i'm not sure why the System.out.println() wouldn't?

And is there a way i can get print() to work. If not, does this mean other processing functions like fill() and rect() won't work?

Any advice would be greatly appreciated!
Re: multiple classes/files in Eclipse
Reply #1 - Aug 20th, 2008, 6:23pm
 
You'd better take one step after the other. I suggest you forget about using Eclipse for Processing for now, grab a halfway decent tutorial on Java programming (there are tons of them on the web, e. g. http://java.sun.com/docs/books/tutorial/), and work your way through that.
Re: multiple classes/files in Eclipse
Reply #2 - Aug 21st, 2008, 12:48am
 
ahhh! *slaps head*,

So now i have named my constructor correctly

import processing.core.*;

public class PrintHelloWorld {
PrintHelloWorld() {
   //print("Hello World"); //THIS DOESNT WORK
System.out.println("Hello World \n3"); // This doesn't appear but compiles
}

}

Thanks for the link brsma, i did Java at uni, but that was  a year ago so i'm a bit rusty. I will brush up on my Java Smiley
However your reply doesn't really help me with my immediate problem of the print() not working. I want to use eclipse so I can easily hook my processing projects up to SVN.

The system.out.println() is working now (because i put it in a function being called), but i still can't use the print().

From errors i have had in the past with the Processing IDE I notice that classes are really an inner-class. Does this mean every class i make will also have to be an inner-class of the processingTest?
Re: multiple classes/files in Eclipse
Reply #3 - Aug 21st, 2008, 2:16am
 
So i've made a bit more progress

The print() function is a static function so i can call it with

PApplet.print("Hello World");

However other functions such as fill() and draw() are not static and are apart of the PApplet class. A solution to this is to either use inner classes or pass a reference to processingTest to the seperate class so it can use its functions
Re: multiple classes/files in Eclipse
Reply #4 - Aug 21st, 2008, 5:05am
 
I have a little tutorial online here about using Processing in eclipse:

http://www.mostpixelsever.com/tutorial/eclipse

This is actually going to move to http://www.learningprocessing.com, but for now it's still at the above link.  Hope this helps!
Re: multiple classes/files in Eclipse
Reply #5 - Aug 21st, 2008, 5:39am
 
Thanks shiffman!

That was pretty much what I wanted to know originally and has supported what I have found out.

The only thing that I can see is with bigger projects, passing the PApplet reference around could get annoying. If allowed to, i would be tempted to use a global variable even though i know its bad. I guess i'll have to have a muck around before i work out the most efficient way.

Thanks once again for the link
Page Index Toggle Pages: 1