Objektorientierte Programmierung WS 2013/2014 - Datei MovableBall.java
import java.awt.*; // MovableBall is a subclass of Ball public class MovableBall extends Ball { // amount of movement per step in x and y direction protected double dx; protected double dy; // constructor public MovableBall(int x, int y, int r) { // uses superclass constructor super(x, y, r); // initializes movement per step dx = 0; dy = 0; } public void setMotion(double ndx, double ndy) { // set the amount of movement per step dx = ndx; dy = ndy; } // functions that access attributes of ball public double xMotion() { return dx; } public double yMotion() { return dy; } public void move() { location.translate((int) dx, (int) dy); } }
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 05.11.2013