Universität Paderborn - Home Universität Paderborn
Die Universität der Informationsgesellschaft

Objektorientierte Programmierung WS 2013/2014 - Datei Ball.java

import java.awt.*;


public class Ball {
    protected Rectangle location;
    protected Color color;

    public Ball(int x, int y, int r) {
        location = new Rectangle(x - r, y - r, 2 * r, 2 * r);
        color = Color.blue;
    }

    // functions that set attributes
    public void setColor(Color newColor) {
        color = newColor;
    }

    // functions that access attributes of ball
    public int radius() {
        return location.width / 2;
    }

    public int x() {
        return location.x + radius();
    }

    public int y() {
        return location.y + radius();
    }

    // functions that change attributes of ball
    public void moveTo(int x, int y) {
        location.setLocation(x, y);
    }

    public Rectangle region() {
        return location;
    }

    public void paint(Graphics g) {
        g.setColor(color);
        g.fillOval(location.x, location.y, location.width, location.height);
    }
}

Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 05.11.2013