|
-
December 5th, 2005, 01:00 AM
#6
Re: Applet ball not moving
 Originally Posted by R3N3G4D3
The problem seems to be that my run() never runs, but I just don't understand why?
run method on the Ball class doesnt get called because you instantiante the class like this Ball ball = new Ball(Xmax, Ymax);
Since it implements the runnable interface you can do somthing like this
Ball ball = new Ball(Xmax, Ymax)
Thread ballThread= new Thread(ball);
now to move the ball just invoke the start method of the ballThread
ballThread.start();
And to keep your ball moving you need a while loop inside the Ball run method to keep updating the ball's x and y coordinates
Or just try editing the Ball constructor
Code:
// just T1 to null;
Thread T1 = null;
public Ball(int a, int b)
{
Xmax = a;
Ymax = b;
x = Xmax/2;
y = Ymax/2;
P1.setPaddle(5, (Ymax/2));
P2.setPaddle((Xmax-5), (Ymax/2));
T1 = new Thread(this);
T1.start();
}
But this might not be a good idea coz.... the ball is already moving even before your applet is being started.......... I think?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|