pinkNoise
YaBB Newbies
Offline
Posts: 8
OOP Woes
Jun 9th , 2005, 12:57am
I am starting to experiment with object-oriented programming within the Processing environment and have made some headway, albeit with much stumbling. At this point, however, I am stuck on this particular problem: I want to initialize a class with a number of parameters that apply to all members of the class, but not to any particular instance. From what I have read, I understand that this can be done with a static method within the class definition, and this method can be invoked something like this: Class.init(params); Here's the source code of a test example: Circle myCircle; float ranColor; void setup(){ size(300,300); background(255); framerate(10); fill(0); noStroke(); ellipseMode(CENTER); myCircle = new Circle(); Circle.init(width/2, height/2, width/2); } void draw(){ ranColor=random(100); myCircle.update(ranColor); } public class Circle{ float xPos; float yPos; float radius; float col; public static void init(float x, float y, float r){ xPos = x; yPos = y; radius = r; } Circle(){ } public void update(float c){ col = c; fill(col); ellipse(xPos, yPos, radius, radius); redraw(); } } The problem is, however, that when I run the sketch, I get the following error: ...Semantic Error: The static method "init" is invalid, because it is enclosed in an inner class, "Circle"... I've tried for a few days to figure this out, but have been unsuccessful. Could someone please show me the way? Thanks, ~BB~