Dieser Code macht den Ball nur vorwärts gehen, wie kann ich den Ball zurückgibt?Making the Ball kehrt zurück in Applet
was ist der Ausdruck, dass ich es der Schleife hinzufügen kann, um den Ball zurück nach links zu machen.
public class NewJApplet extends JApplet {
public void paint(Graphics g)
{
final int X=0;
final int Y=50;
final int DIAMETER=15;
final Color COLOR= Color.BLACK;
final int SPACE =5;
// instantiate the ball as a Circle object
Circle baall = new Circle(X,Y,DIAMETER,COLOR);
// get ball diameter and width & height of the applet window
int ballDiam = baall.getDiameter();
int windWidth= getWidth();
int windHeight=getHeight();
// rolling horizontally
// check whether ball is at right edge of window
while(baall.getX()+ballDiam<windWidth)
{
baall.draw(g);
try {
Thread.sleep(50);
} catch (Exception e) {
System.out.println("There is an error in sleep ! ");
}
// clear the window
g.clearRect(0, 0, windWidth, windHeight);
// position to next location for drawing ball
baall.setX(baall.getX()+SPACE);
}
baall.draw(g); // draw the ball in the current position
}
}
Für eine bessere Hilfe :) gut funktionieren, senden Sie uns eine [MCVE] oder [Kurz, Self Contained , Korrektes Beispiel] (http://www.sscce.org/). –