Site hosted by Angelfire.com: Build your free website today!
 

The Graphic Element Classes

There is no change to the GraphicElement interface

package graphicalobject;
/*
 * This defines the behavior of a generic graph element
 */
public interface GraphicElement {
    public Coordinate getPosition();
    public void move(Coordinate coord);
    abstract public void display();
}

The BaseGraphicElem and the Coordinate class now also implements the Serializable interface

package graphicalobject;

import java.io.Serializable;

abstract public class BaseGraphicElem
    implements GraphicElement, Serializable {
    private Coordinate location = new Coordinate(0, 0);
    public Coordinate getPosition() {
        return location;
    }
    public void move(Coordinate coord) {
        location.x = coord.x;
        location.y = coord.y;
    }
    public void display() {
        System.out.print(getClass().getName() + ":" + location.toString());
    }
}
package graphicalobject;

import java.io.Serializable;

public class Coordinate implements Serializable{
    protected int x;
    protected int y;

    public Coordinate(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public void setCoordinate(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public String toString() {
        return " x=" + x + ", y=" + y;
    }
}