package chap6;
import java.util.Iterator;
import java.util.Vector;
abstract class GraphicObject {
int x, y, w, h;
public GraphicObject(int x, int y, int w, int h) {
super();
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
public abstract void view();
}
class Rect extends GraphicObject {
public Rect(int x, int y, int w, int h) {
super(x, y, w, h);
}
@Override
public void view() {
System.out.println(x + "," + y + " -> " + w + "," + h + "의 사각형");
}
}
class Line extends GraphicObject {
public Line(int x, int y, int w, int h) {
super(x, y, w, h);
}
@Override
public void view() {
System.out.println(x + "," + y + " -> " + w + "," + h + "의 선");
}
}
public class Ex6 {
Vector<GraphicObject> v = new Vector<GraphicObject>();
void add(GraphicObject ob) {
v.add(ob);
}
void draw() {
Iterator<GraphicObject> it = v.iterator();
while (it.hasNext()) {
it.next().view();
}
}
public static void main(String[] args) {
Ex6 g = new Ex6();
g.add(new Rect(2, 2, 3, 4));
g.add(new Line(3, 3, 8, 8));
g.add(new Line(2, 5, 6, 6));
g.draw();
}
}