Dear i want to make a program i which when Pressed UP Arrow key cicle start moving up and when pressed DOWM key circle moves Downword Similarly left and right i have draw circle and also implements Key Listner and can anyone give me ideo how i do this task here is my code.
import java.awt.Graphics;
import javax.swing.JFrame;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
class MovingBalls extends JFrame implements KeyListener
{
public MovingBalls()
{
setTitle(":: Move ball With Keyboard Input ::");
setVisible(true);
setBounds(100,100,500,500);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void paint(Graphics g){
g.drawOval(40, 40, 60, 60);
g.fillOval(40, 40, 60, 60);
g.addKeyListener(this);
}
public void keyPressed(KeyEvent ke1)
{
}
public void keyTyped(KeyEvent ke2){}
public void keyReleased(KeyEvent ke3){}
public static void main(String abc[])
{
MovingBalls MB = new MovingBalls();
}
}