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

📄 poly.java

📁 利用java编写的paintbox小程序
💻 JAVA
字号:
/*
 * Poly.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.*;
import java.util.*;

public class Poly extends Shape{
    
    /** Creates a new instance of Poly */
   private ArrayList xList = new ArrayList ();
   private ArrayList yList = new ArrayList ();
   
   public Poly (Color color, int x, int y)
   {
      strokeColor = color;
      xList.add (new Integer (x));
      yList.add (new Integer (y));
   }

   public void addPoint (int x, int y)
   {
      xList.add (new Integer (x));
      yList.add (new Integer (y));
   }
   
   public void updateLastPoint (int x, int y)
   {
      xList.remove (xList.size ()-1);
      xList.add (new Integer (x));
      yList.remove (yList.size ()-1);
      yList.add (new Integer (y));
   }   
  
   public void draw (Graphics page)
   {
      int[] xtemp = new int[xList.size ()];
      int[] ytemp = new int[yList.size ()];

      //  Get the end points of the line segments and store them
      for (int index = 0; index < xList.size (); index++)
      {
         xtemp[index] = ((Integer) xList.get (index)).intValue ();
         ytemp[index] = ((Integer) yList.get (index)).intValue ();
      }

      //  Set the stroke color and draw the lines
      page.setColor (strokeColor);
      page.drawPolyline (xtemp, ytemp, xList.size ());
      if(slected)
      {
          int x,y;
          page.setColor(Color.BLACK);
          for(int m=0; m<xList.size(); m++){
           x=((Integer)xList.get(m)).intValue();
           y=((Integer)yList.get(m)).intValue();
           page.fillOval(x-3,y-3,6,6);
          }
             
      }
   }   
   
   public  boolean isSlected(Point point)
   {
       boolean s=false;
       int x,y;
       for(int i=0; i<xList.size(); i++)
       {
           x=((Integer)xList.get(i)).intValue();
           y=((Integer)yList.get(i)).intValue();
           s=(Math.abs(point.x-x)<10)&&(Math.abs(point.y-y)<10);
           if(s)
               break;
       }

       return s;
   }
   
    public  void positionChanged(int xChanged, int yChanged)
    {
        int m,n;
        for(int x=0; x<xList.size(); x++){
            m=((Integer)xList.get(x)).intValue();
            n=((Integer)yList.get(x)).intValue();
            
            xList.remove(x);
            xList.add(x,new Integer(m+xChanged));
            yList.remove(x);
            yList.add(x,new Integer(n+yChanged));
        }
    }
    
    public Object clone()
   {
       D d=new D();
       return d.getPoly();
   }


  private class D 
  {
      private Poly poly;
      public D()
      {
          poly=new Poly(strokeColor,((Integer)xList.get(0)).intValue(),((Integer)yList.get(0)).intValue());
          for(int i=1; i<xList.size(); i++)
          poly.addPoint(((Integer)xList.get(i)).intValue(),((Integer)yList.get(i)).intValue());
      }
    
     public Poly getPoly()
     {
         return poly;
     }
   }
}






⌨️ 快捷键说明

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