package sunw.demo.hotspots; import java.awt.*; import java.util.*; public class LineShape extends Shape implements Observer { HotSpot _hs1, _hs2; int _x1, _y1, _x2, _y2; public LineShape(int x1, int y1, int x2, int y2) { _x1 = x1; _y1 = y1; _x2 = x2; _y2 = y2; _hs1 = new HotSpot(new Coordinates(x1, y1)); _hs2 = new HotSpot(new Coordinates(x2, y2)); _hs1.addObserver(this); _hs2.addObserver(this); } public Vector getHotSpots() { Vector vec = new Vector(); vec.addElement(_hs1); vec.addElement(_hs2); return vec; } public void paint(Graphics g) { g.drawLine(_x1, _y1, _x2, _y2); } public void update(Observable obs, Object obj) { Coordinates coord1 = _hs1.getCoordinates(); Coordinates coord2 = _hs2.getCoordinates(); if (obs == _hs1) { _x1 = coord1.x; _y1 = coord1.y; } else if (obs == _hs2) { _x2 = coord2.x; _y2 = coord2.y; } _hs1.setCoordinates(new Coordinates(_x1, _y1)); _hs2.setCoordinates(new Coordinates(_x2, _y2)); } }