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 & HelpPrograms › Why does this program run
Page Index Toggle Pages: 1
Why does this program run? (Read 861 times)
Why does this program run?
Jun 3rd, 2005, 6:00pm
 
I'm just curious about the way processing/java works. How is 'a' accessed when there is no object of Begin for it to exist in? Is an object of Begin created sometime without the user's knowledge?

Code:


public class Begin extends PApplet {

int a=200;

void setup()
{
size(a, 200);

rectMode(CENTER);
noStroke();
fill(0, 102, 153, 204);
}

void draw()
{
background(255);
rect(width-mouseX, height-mouseY, 50, 50);
rect(mouseX, mouseY, 50, 50);
}
}



Re: Why does this program run?
Reply #1 - Jun 3rd, 2005, 7:03pm
 
What you have there is a class definition. Class definitions are blueprints for objects.

When you create an object of a class you call its constructor and it reserves space in memory  for all the values used in the object.

So in your class definition below, you're saying that all objects of Begin will have an interger a, that will need to be reserved.

So to answer your question, there would be a line such as:
Begin test = new Begin();
test.setup();
test.draw();
...
This is probably in a main method definition somewhere else. Generally speaking you don't have to worry about Processing handles this. Its more important if you want to create your own class/object definitions. The processing crew have tried to simplify the interface as much as possible.
Re: Why does this program run?
Reply #2 - Jun 3rd, 2005, 8:31pm
 
thanks markavian, i suspected that.
Page Index Toggle Pages: 1