Q.1 Say you create a blank class that extends JApplet called BallApplet.
In BallApplet you create an Instance of a 'Ball'. The constructor for Ball takes a reference to the applet which created it (BallApplet) Is it possible for an Instance of Ball to paint onto the applet. I can only seem to do any painting actually in the void paint(Graphics g) method of the BallApplet class. If I insert this into the Ball.class it doesn't work.
appletThatCreatedBall.getGraphics().drawRect(10,10,10,10);
appletThatCreatedBall being the reference passed to the Ball's constructor.
Any ideas?
Q.2 If you had a loop:
while (go)
go being a boolean set to true. If the while loop were to perform some very long process, I can't quit the loop by having the KeyListener detect a kep press and changed go to false.
Will I need multiple threads? I presume the key press event isn't being fired because the loop is running in the same thread, therefore not terminating the loop.
What is the simplest way to terminate a long loop by user intervention? Obviously I could limit the iterations with a for loop, but I want it to run until the user intervenes.
multiple classes still run on a single thread don't they?
Thanks alot
Dom.
In BallApplet you create an Instance of a 'Ball'. The constructor for Ball takes a reference to the applet which created it (BallApplet) Is it possible for an Instance of Ball to paint onto the applet. I can only seem to do any painting actually in the void paint(Graphics g) method of the BallApplet class. If I insert this into the Ball.class it doesn't work.
appletThatCreatedBall.getGraphics().drawRect(10,10,10,10);
appletThatCreatedBall being the reference passed to the Ball's constructor.
Any ideas?
Q.2 If you had a loop:
while (go)
go being a boolean set to true. If the while loop were to perform some very long process, I can't quit the loop by having the KeyListener detect a kep press and changed go to false.
Will I need multiple threads? I presume the key press event isn't being fired because the loop is running in the same thread, therefore not terminating the loop.
What is the simplest way to terminate a long loop by user intervention? Obviously I could limit the iterations with a for loop, but I want it to run until the user intervenes.
multiple classes still run on a single thread don't they?
Thanks alot
Dom.