I am trying to start a small animation on mouse click ...here is my code
import acm.graphics.*;
import acm.program.*;
import java.awt.*;
import acm.util.*;
import java.awt.event.*;
public class ClickAnimation extends GraphicsProgram {
GOval ball=new GOval(50,50,50,50);
public void run() {
add(ball);
addMouseListeners();
}
public void mouseClicked(MouseEvent e) {
while(ball.getX()<getWidth()) {
ball.move(0.2,0.2);
pause(10);
}
}
}
Google says while loop cannot be used inside a mouse listener...how can i fix this?