Java Swing Layout Manager Event Handling Inner Classes Swing Applet Exceptions Threads Java I/O![]() Stream![]() Character Stream classes![]() Byte Stream classes![]() I/O Methods![]() Type of I/O![]() File Streams![]() Data Streams![]() Object Serialization![]() Writing and Read Object![]() Drawing Editor Revisit![]() Drawing Editor Revisit![]() The Draw Class![]() The Graphic Element Classes![]() The Element Implementation classes![]() Transient Fields Network Programming Resources | The Graphic Element ClassesThere 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;
}
}
|