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
Simple Class (Read 671 times)
Simple Class
Jan 18th, 2007, 10:34pm
 
I need to create a series of classes to be called into one file. I was just wondering how you go about actually making a class?

Do you make one in processing or outside in a java file?

Any help would be really grateful.
Re: Simple Class
Reply #1 - Jan 18th, 2007, 10:54pm
 
Quote:
I need to create a series of classes to be called into one file...Do you make one in processing or outside in a java file...

Bit weird that question. Maybe you want a primer on Object Orientated Code

The java file stuff is just handy for when you start taking projects in and out of Processing. In a .java file tab you would need to use proper Java syntax, not the easy Processing stuff (ie: if you're not building a library, I doubt you need it). And each class would be in a separate file of the same name as the class.

But in Processing, the stuff you're making is inner classes of a big class called PApplet. Hence we can have all these .pde files and stick almost any old rubbish in any old order in them.
Re: Simple Class
Reply #2 - Jan 18th, 2007, 11:40pm
 
you can have .java files inside Processing, too. just make a new tab and give it a name ending in .java like: "MyFancyObject.java"

that way you push that file into the compiler seperated from all the pde files (which will all be concatenated into one file, then preprocessed into java and then passed to the compiler). inside your "seperate" .java files you can do just any "normal" java stuff. to have it interact with the pde(s), you will have to pass it the applet as parameter, like:

tab MyFancyObject.java
Code:

import processing.core.*;

public class MyFancyObject
{
   PApplet parent;
   MyFancyObject ( PApplet _p )
   {
       this.parent = _p;
   }
   public float getFrameRateFromParent()
   {
       return parent.frameRate;
   }
}


your sketch code
Code:

void setup ()
{
   MyFancyObject mfo = new MyFancyObject( this );
   println( mfo.getFrameRateFromParent() );
}


you can see what's happening behind the curtains if you export you sketch for web and than look into the generated "<yoursketchname>.java" file inside the applet folder ... i hope this was not too detailed.

F
Re: Simple Class
Reply #3 - Jan 19th, 2007, 12:02pm
 
Thats perfect thanks!
Page Index Toggle Pages: 1