compilation error caused by implementing interfaces
in
Programming Questions
•
3 years ago
Hi,
i´m trying to programm a simple observer pattern. I use toxi´s verlet physics lib and try to connect particles via an observer pattern, so they can communicate with one another. I want to achieve different agent behavior that can change dependent on messages an agent recieves. I´m at the very beginning and don´t really know where it will lead me to, so i try to programm something really basic that can be easily extended. But at the moment i always get an exception that say´s
"unexpected token void" at my "void setup(){" line.
When i comment out my interfaces and all the stuff which has to do with it, no problem no more. But i can´t find any syntax error or something like that. Maybe i´m to blind, or maybe i don´t know enough about the usage of interfaces. I don´t know, so help is really welcome. I´m using Processing 1.2.1 (with java) on a windows 7 64bit system.
i´m trying to programm a simple observer pattern. I use toxi´s verlet physics lib and try to connect particles via an observer pattern, so they can communicate with one another. I want to achieve different agent behavior that can change dependent on messages an agent recieves. I´m at the very beginning and don´t really know where it will lead me to, so i try to programm something really basic that can be easily extended. But at the moment i always get an exception that say´s
"unexpected token void" at my "void setup(){" line.
When i comment out my interfaces and all the stuff which has to do with it, no problem no more. But i can´t find any syntax error or something like that. Maybe i´m to blind, or maybe i don´t know enough about the usage of interfaces. I don´t know, so help is really welcome. I´m using Processing 1.2.1 (with java) on a windows 7 64bit system.
- import toxi.geom.*;
import toxi.physics.*;
import processing.opengl.*;
VerletPhysics physics;
Vec3D gravity;
DropBall ballA,ballB;
void setup(){
size(800,400,OPENGL);
physics = new VerletPhysics();
physics.setGravity(new Vec3D(0,0.1,0));
physics.setWorldBounds(new AABB(new Vec3D(0,0,0),new Vec3D(width,height,100)));
ballA = new DropBall(width/3,0.f,0.f);
ballB = new DropBall((width/3)*2,100.f,0.f);
ballA.addSubject(ballB);
ballB.addObserver(ballA);
physics.addParticle(ballA);
physics.addParticle(ballB);
}
void draw(){
physics.update();
background(0);
ballA.display();
ballB.display();
}- class Agent extends VerletParticle implements Observer, Subject{
ArrayList lsObserver, lsSubject, data;
Agent(float x, float y, float z){
super(x,y,z);
lsObserver = new ArrayList();
lsSubject = new ArrayList();
data = new ArrayList();
}
//-----------------------------------------------------
//Observer methods
void addSubject(Subject s){
lsSubject.add(s);
}
Subject updateData(Subject s,ArrayList data){
this.data = data;
return s;
}
ArrayList getData(){
return data;
}
//----------------------------------------------------
//Subject methods
void addObserver(Observer o){
lsObserver.add(o);
}
void deleteObserver(Observer o){
int i = lsObserver.indexOf(o);
if(i>=0){
lsObserver.remove(o);
}
}
void sendData(){
for(int i=0;i<lsObserver.size();i++){
Observer o = (Observer) lsObserver.get(i);
o.updateData(this,data);
}
} - }
class DropBall extends Agent{
DropBall(float x, float y, float z){
super(x,y,z);
}
void display(){
stroke(255);
pushMatrix();
translate(x,y,z);
beginShape(LINES);
vertex(-10,0,0);
vertex(10,0,0);
vertex(0,-10,0);
vertex(0,10,0);
vertex(0,0,-10);
vertex(0,0,10);
endShape();
popMatrix();
}
void doSomething(){
print("i am a drop ball at position: " + x + ", " + y + ", " + z + "/n");
}
} - interface Observer{
void addSubject(Subject s);
Subject updateData(Subject s,ArrayList l);
ArrayList getData();
} - interface Subject{
void addObserver(Observer o);
void deleteObserver(Observer o);
void sendData();
}
1

, but unfortunately that does not correct the compilation error. I think it has something to do with the interfaces. At first it worked, but when i changed something on the interface methods it didn´t work anymore and when i comment the interfaces out with everything that has to do with them there is no compilation error anymore.