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.
Page Index Toggle Pages: 1
PApplet madness (Read 1270 times)
PApplet madness
Dec 7th, 2009, 6:26pm
 
Hello,

I just started reading about PApplet in ch14 of the Ira Greenberg book and I'm pretty confused. Is PApplet a java class? Are ALL of Processing's functions included as methods in this class? Where is PApplet? How does it get bundled with the rest of the stuff when you hit File > Export?

I think I need to get some sleep and start again fresh tomorrow.
Re: PApplet madness
Reply #1 - Dec 8th, 2009, 1:16am
 
Quote:
Is PApplet a java class?

Yes it is.

Quote:
Are ALL of Processing's functions included as methods in this class?

Sure. Everything like setup(), draw(), line(...) are methods in this class.

Quote:
Where is PApplet?

It's here, in the source code of Processing :
http://dev.processing.org/source/index.cgi/trunk/processing/core/src/processing/core/PApplet.java?view=markup

Quote:
How does it get bundled with the rest of the stuff when you hit File > Export?

The PDE does its magic. Basically, everytime you compile a sketch, the PDE will wrap your code into an extended PApplet class, add Processing's libraries that are needed to run the stuff, and will put all that stuff in a jar file.
Re: PApplet madness
Reply #2 - Dec 8th, 2009, 10:47am
 
Cool thanks!

antiplastik wrote on Dec 8th, 2009, 1:16am:
The PDE does its magic. Basically, everytime you compile a sketch, the PDE will wrap your code into an extended PApplet class, add Processing's libraries that are needed to run the stuff, and will put all that stuff in a jar file.


That's quite magical indeed.

EDIT: wait one more question: if everything gets converted to Java and put into a .jar file (everything becomes an inner class), then why does the applet folder include separate Processing Source Code files for each of your Processing classes Aren't these already in the .jar file
Re: PApplet madness
Reply #3 - Dec 8th, 2009, 11:18am
 
Yes - but you need them in text form so people can see the source (which you might have noticed gets added to the exported webpage by default Wink )
Re: PApplet madness
Reply #4 - Dec 8th, 2009, 12:03pm
 
Phattee wrote on Dec 8th, 2009, 10:47am:
if everything gets converted to Java and put into a .jar file (everything becomes an inner class)


Your sketch becomes an extended PApplet. The classes you have coded in your sketch become inner classes of this extended PApplet.

Say you have a sketch - mySketch - like this :
Code:
int a = 0;
void setup() {}
void draw() {}
class A {}


Then the Java code after compiling will be something like :
Code:
import processing.core.*;
// import other needed libraries

public class mySketch extends PApplet {
 int a = 0;
 public void setup() {}
 public void draw() {}
 class A {}
}


Actually, you can have a look at the resulting .java file, since it is exported too next to the .jar archive (look into the /applet folder, you should find mySketch.jar and precompiled mySketch.java).
Re: PApplet madness
Reply #5 - Dec 8th, 2009, 12:38pm
 
Thank you! Ok last questions I promise. I guess these are more like Java questions:

So the .jar file is a self-contained executable file, it doesn't need to be in a folder with any other files? The files that end in .java or .pde are just there so people can read the code?
Re: PApplet madness
Reply #6 - Dec 8th, 2009, 1:15pm
 
Yes. Just give it a try!
Page Index Toggle Pages: 1