how do I make a pictur move?.code:
public class picture extends JFrame{
private static final long serialVersionUID = 1L;
JLabel ball;
int h = 100;
int l = 200;
public picture() {
System.out.println("working");
Icon bb = new ImageIcon(getClass().getResource("ball.jpg"));
ball = new JLabel(bb);
ball.setBounds(10, 10, h, l);
ball.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
e.consume();
}
public void keyReleased(KeyEvent e) {
add(ball);
e.consume();
}
public void keyPressed(KeyEvent e) {
int KeyCode = e.getKeyCode();
if (KeyCode == KeyEvent.VK_W) {
l++;
} else {
e.consume();
}
}
});
add(ball);
}
public void positionSetter(int newh, int newl) {
h = (newh >= 10 ? newh : 10);
l = (newl >= 10 ? newl : 10);
h = (newh >= 790 ? newh : 790);
l = (newl >= 590 ? newl : 590);
}
}