⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 line.java

📁 利用java编写的paintbox小程序
💻 JAVA
字号:
/*
 * Line.java
 *
 * Created on 2007年4月23日, 下午11:57
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package paintbox;

/**
 *
 * @author fly
 */
import java.awt.*;

public class Line extends Shape{
    
    /** Creates a new instance of Line */
    
   private Point firstPoint;
   private Point secondPoint;
   
   public Line (Color color, Point p1, Point p2)
   {
       super();
      strokeColor = color;
      firstPoint = p1;
      secondPoint = p2;
   }
   
   public void setEndPoint (Point endPoint)
   {
     secondPoint = endPoint;
   } 
   
   public void draw (Graphics page)
   {
      page.setColor (strokeColor);
      page.drawLine (firstPoint.x, firstPoint.y, secondPoint.x,
                     secondPoint.y);
      if(slected)
      {
          page.setColor(Color.BLACK);
          page.fillOval(firstPoint.x-3,firstPoint.y-3,6,6);
          page.fillOval(secondPoint.x-3,secondPoint.y-3,6,6);
      }
   }
   
   public void positionChanged(int xChanged, int yChanged)
   {
      firstPoint.x+=xChanged;
      firstPoint.y+=yChanged;
      secondPoint.x+=xChanged;
      secondPoint.y+=yChanged;
   }
   
   public  boolean isSlected(Point point)
   {
       boolean s=false;
       s=(Math.abs(point.x-firstPoint.x)<10)&&(Math.abs(point.y-firstPoint.y)<10) ||
                                  (Math.abs(point.x-secondPoint.x)<10)&&(Math.abs(point.y-secondPoint.y)<10);
       return s;
   }
   
   public Object clone()
   {
       A a=new A();
       return a.getLine();

   }


   private class A 
  {
      public Line line;
      public A()
      {
          Point point1=new Point(firstPoint.x, firstPoint.y);
          Point point2=new Point(secondPoint.x, secondPoint.y);
          line=new Line(strokeColor,point1,point2);
      }
    
     public Line getLine()
     {
         return line;
     }
   }
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -