User inputs and simple anim.
I know this is a bit basic, but I'm having trouble getting this animation to respond to user inputs. I want the circle to start near the centre of the screen and move up until it hits Y less than 10. Here, I've started the animation thread as a response to the user input, I know this probably isn't the best way to do it.
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.*;
import java.awt.event.*;
publicclass basicAnimationextends Appletimplements Runnable, KeyListener
{Thread aThread;
publicint Y;
publicvoid start()
{
if (aThread ==null)
{aThread =new Thread(this);
aThread.start();}
}
publicvoid stop()
{
if (aThread !=null)
{aThread =null;}
}
publicvoid run()
{
while (true)
{
for(Y=350; Y<10; Y--)
{repaint();
try{ Thread.sleep(100);}
catch (InterruptedException e){}}
}
}
publicvoid init()
{Y=350;}
publicvoid paint(Graphics g)
{g.fillOval (415, Y, 10, 10);}
publicvoid keyPressed(KeyEvent e)
{
int keyCode = e.getKeyCode();
switch(keyCode)
{case KeyEvent.VK_SPACE:
aThread.start();
break;}
}
publicvoid keyTyped(KeyEvent e){}
publicvoid keyReleased(KeyEvent e){}
}

