/* Programmer: Konstantin Lukin e-mail : lukink@ug.cs.sunysb.edu */ import java.awt.*; public class Arrow extends Rectangle { // position (orientation) of the Arrow public static int EAST = 1; public static int WEST = 2; public static int NORTH = 3; public static int SOUTH = 4; // Constructor public Arrow(int x, int y, int width, int height, int orien) { super(x, y, width, height); this.orientation = orien; poly = new Polygon(); setArrow(); } public void setOrientation(int new_orient) { orientation = new_orient; setArrow(); } public void draw(Graphics g) { g.drawPolygon(poly); } public void fill(Graphics g) { g.fillPolygon(poly); } private void setArrow() { Point p1, p2, p3; switch(orientation) { case 1: p1 = new Point(x, y); p2 = new Point(x+width, y+height/2); p3 = new Point(x, y+height); break; case 2: p1 = new Point(x+width, y); p2 = new Point(x, y+height/2); p3 = new Point(x+width, y+height); break; case 3: p1 = new Point(x, y+height); p2 = new Point(x+width/2, y); p3 = new Point(x+width, y+height); break; case 4: p1 = new Point(x, y); p2 = new Point(x+width/2, y+height); p3 = new Point(x+width, y); break; default: System.out.println("Arrow ==> error in setArrow"); p1 = new Point(x, y); p2 = new Point(x+width/2, y+height); p3 = new Point(x+width, y); } poly.addPoint(p1.x, p1.y); poly.addPoint(p2.x, p2.y); poly.addPoint(p3.x, p3.y); poly.addPoint(p1.x, p1.y); // when drawing, complete polygon } private int orientation = 1; // default private Polygon poly; }