示例#1
0
 public void mouseDragged(MouseEvent e) {
   int x = e.getX(), y = e.getY(), dx = lastX - x, dy = lastY - y;
   lastX = x;
   lastY = y;
   if (first == null) {
     Line line = addLine(point1, new Point(x, y));
     if (line != null) {
       canvas.add(line.getP2());
       first = line.getP2();
       canvas.add(line);
     }
   } else {
     first.move(-dx, -dy);
   }
   repaint();
 }
示例#2
0
 private FigureElement findFigureElement(int x, int y) {
   Point2D p = new Point2D.Float((float) x, (float) y);
   for (Iterator i = canvas.members(); i.hasNext(); ) {
     FigureElement fe = (FigureElement) i.next();
     if (fe.contains(p)) return fe;
   }
   return null;
 }
示例#3
0
 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   g2.setPaint(BACKGROUND);
   g2.fill(
       new Rectangle2D.Float(
           0f, 0f, (float) g2.getClipBounds().width, (float) g2.getClipBounds().height));
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   canvas.paint(g2);
 }
示例#4
0
    private Line addLine(Point p1, Point p2) {
      if (Math.abs(p1.getX() - p2.getX()) < 5 || Math.abs(p1.getY() - p2.getY()) < 5) {
        return null;
      }

      Line line = null;
      if (p1 != null && p2 != null) {
        line = new Line(p1, p2);
        canvas.add(line);
      }
      repaint();
      return line;
    }
示例#5
0
 private Point addPoint(int x, int y) {
   Point p = new Point(x, y);
   canvas.add(p);
   repaint();
   return p;
 }