Dear Experts,
I am working on a distributed animation of moving BALLS with RMI.
My goal is to move multiple balls in a way, so that multiple clients observe the same movement/position of balls, i m using ball object which is remote object.
The ball is moving fine, when it is only one, but when i m trying to increase the number of balls, i m failing.
here are some code snippets where i applied loops to work for multiple balls:
on server:
b[0] = new BallImpl(0, 50, 2, 3 ,Color.YELLOW,20);
b[1] = new BallImpl(50, 50, 4, 3,Color.BLUE,10);
b[2] = new BallImpl(40, 40, 5, 5, Color.PINK,30);
b[3] = new BallImpl(60, 70, 4, 6, Color.GREEN,40);
for (int i = 0; i < currentNumBalls; i++) {
Naming.rebind ("rmi://localhost/BouncingBall", b[i]); // registers Ball object
System.out.println ("remote ball object registered.");
}
on client site :
that how i look up for remote balls:
for (int i = 0; i < currentNumBalls; i++) {
try {
this.aBall[i] = (Ball) Naming.lookup("rmi://localhost/BouncingBall");
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
start();
thats moving balls code:
public void moveballs() {
for (int i = 0; i < currentNumBalls; i++) {
try {
aBall[i].setBounds(pit.getWidth(), pit.getHeight());
aBall[i].move();
pit.repaint();
} catch (Exception e) {
e.printStackTrace();
}
}
}
and that's the drawing code:
public void drawballs(Graphics g) {
for (int i = 0; i < currentNumBalls; i++) {
try {
g.setColor(aBall[i].getColor());
g.fillOval(aBall[i].getX(), aBall[i].getY(), aBall[i].getradius(), aBall[i].getradius());
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
Can somebody please guide me why i can see only one ball moving, what about other balls or there is some problem in this design and i m using the RMI in wrong way? or recommend me some design by which i can accomplish my goal.
thanks a lot,
jibby