Source of Stroke.java


  1: 
  2: package scribble3; 
  3: 
  4: import java.util.*;
  5: import java.awt.Point;
  6: import java.awt.Color;
  7: import java.awt.Graphics;
  8: 
  9: public class Stroke extends Shape { 
 10: 
 11:   public Stroke() {} 
 12:   
 13:   public Stroke(Color color) {
 14:     super(color); 
 15:   } 
 16: 
 17:   public void addPoint(Point p) {
 18:     if (p != null) { 
 19:       points.add(p); 
 20:     }
 21:   }
 22: 
 23:   public List getPoints() { 
 24:     return points; 
 25:   }
 26: 
 27:   public void draw(Graphics g) {
 28:     if (color != null) {
 29:       g.setColor(color);
 30:     }
 31:     Point prev = null; 
 32:     Iterator iter = points.iterator(); 
 33:     while (iter.hasNext()) { 
 34:       Point cur = (Point) iter.next(); 
 35:       if (prev != null) {
 36:         g.drawLine(prev.x, prev.y, cur.x, cur.y); 
 37:       }
 38:       prev = cur; 
 39:     }
 40:   }
 41: 
 42:   // The list of points on the stroke
 43:   // elements are instances of java.awt.Point 
 44:   protected List points = new ArrayList();  
 45:   
 46: }