可以用Java Media APIs,它里面有一个Java 2D API,这个函数包可以实现绘制平面图形,我给你写个例子吧,:)import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import java.awt.font.TextLayout;
import java.awt.font.FontRenderContext;
import javax.swing.*;
public class Dash extends JApplet {    public void init() {
        setBackground(Color.white);
    }
    public void drawDemo(int w, int h, Graphics2D g2) {        FontRenderContext frc = g2.getFontRenderContext();
        Font font = g2.getFont();
        TextLayout tl = new TextLayout("Dashes", font, frc);
        float sw = (float) tl.getBounds().getWidth();
        float sh = (float) tl.getAscent() + tl.getDescent();
        g2.setColor(Color.black);
        tl.draw(g2, (float) (w/2-sw/2), sh+5);
        BasicStroke dotted = new BasicStroke(3, BasicStroke.CAP_ROUND, 
                     BasicStroke.JOIN_ROUND, 0, new float[]{0,6,0,6}, 0);
        g2.setStroke(dotted);
        g2.drawRect(3,3,w-6,h-6);        int x = 0; int y = h-34;
        BasicStroke bs[] = new BasicStroke[6];        float j = 1.1f;
        for (int i = 0; i < bs.length; i++, j += 1.0f) {
            float dash[] = { j };
            BasicStroke b = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, 
                                BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
            g2.setStroke(b);
            g2.drawLine(20, y, w-20, y);
            bs[i] = new BasicStroke(3.0f, BasicStroke.CAP_BUTT, 
                                BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
            y += 5;
        }        Shape shape = null;
        y = 0;
        for (int i = 0; i < 6; i++) {
            x = (i == 0 || i == 3) ? (w/3-w/5)/2 : x + w/3;
            y = (i <= 2) ? (int) sh+h/12 : h/2;            g2.setStroke(bs[i]);
            g2.translate(x, y);  
            switch (i) {
                case 0 : shape = new Arc2D.Float(0.0f, 0.0f, w/5, h/4, 45, 270, Arc2D.PIE);
                         break;
                case 1 : shape = new Ellipse2D.Float(0.0f, 0.0f, w/5, h/4);
                         break;
                case 2 : shape = new RoundRectangle2D.Float(0.0f, 0.0f, w/5, h/4, 10.0f, 10.0f);
                         break;
                case 3 : shape = new Rectangle2D.Float(0.0f, 0.0f, w/5, h/4);
                         break;
                case 4 : shape = new QuadCurve2D.Float(0.0f,0.0f,w/10, h/2,w/5,0.0f);
                         break;
                case 5 : shape = new CubicCurve2D.Float(0.0f,0.0f,w/15,h/2, w/10,h/4,w/5,0.0f);
                         break;
            }            g2.draw(shape);
            g2.translate(-x, -y);
        }
    }
    public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
Dimension d = getSize();
        g2.setBackground(getBackground());
        g2.clearRect(0, 0, d.width, d.height);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        drawDemo(d.width, d.height, g2);
    }
    public static void main(String argv[]) {
        final Dash demo = new Dash();
        demo.init();
        JFrame f = new JFrame("Java 2D(TM) Demo - Dash");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        });
        f.getContentPane().add("Center", demo);
        f.pack();
        f.setSize(new Dimension(400,300));
        f.show();
    }
}

解决方案 »

  1.   

    箭头已经画好,序列化有点头疼,那位帮忙写一下,代码如下:public class Arrow3 extends Entity{  Point UpEnd,DownEnd;
      Polygon p;
      public Arrow3(Point start, Point end, Color color,float lineWidth)
         {
           super(color,lineWidth);
           position = new Point(Math.min(start.x, end.x), Math.min(start.y, end.y));
           createPath(position,end);     }
         public java.awt.Rectangle getBounds()
         {
           return getBounds(arrow3.getBounds());     }     Point  RotatePoint( Point srcPoint, Point basePoint,
                                                       double dAngle)
         {// 求得源点srcPoint绕basePoint旋转dAngle角度后的点
                  Point p=new Point();
                 double cosv = Math.cos(dAngle) ; // cos value
                 double sinv = Math.sin(dAngle) ;
                 p.x =(int)(srcPoint.x * cosv - srcPoint.y * sinv +
                           (1.- cosv) * basePoint.x + basePoint.y * sinv);
                 p.y =(int)(sinv * srcPoint.x + cosv * srcPoint.y +
                           (1.- cosv) * basePoint.y - sinv * basePoint.x);
                 return p;
    }
          public  void createPath(Point start,Point end) {
            Point PointRotate=new Point();               double dDist=Math.sqrt((end.x-start.x)*
                                         (end.x-start.x)+
                                                     (end.y-start.y)*
                                                     (end.y-start.y));
                   if (dDist<1.0) dDist=1.0;
                   double dRatio=14/dDist;
                   PointRotate.x=(int)((end.x-start.x)*dRatio+end.x);
                   PointRotate.y=(int)((end.y-start.y)*dRatio+end.y);
                   UpEnd=RotatePoint(PointRotate,end,-Math.PI*7/8);
                  DownEnd=RotatePoint(PointRotate,end,Math.PI*7/8);         Point2D.Float  point=new Point2D.Float();
            arrow3=new GeneralPath();
            arrow3.moveTo(0,0) ;
            arrow3.lineTo(end.x-position.x,end.y-position.y) ;
            point=(Point2D.Float)arrow3.getCurrentPoint();
            arrow3.lineTo(UpEnd.x-position.x,UpEnd.y-position.y);
            arrow3.moveTo(point.x,point.y) ;
            arrow3.lineTo(DownEnd.x-position.x,DownEnd.y-position.y);
            int[] xPoints=new int[3];
            int[] yPoints=new int[3];
             xPoints[0]=UpEnd.x-position.x;
             yPoints[0]=UpEnd.y-position.y;
             xPoints[1]=DownEnd.x-position.x;
             yPoints[1]=DownEnd.y-position.y;
             xPoints[2]=end.x-position.x;
             yPoints[2]=end.y-position.y;
             p=new Polygon(xPoints,yPoints,3);
             arrow3.append(p,false);      }     public void modify(Point start, Point end)
         {
           createPath(position,end);
          }
         public void draw(Graphics2D g2D)
         {
           AffineTransform old = g2D.getTransform();           // Save the current transform  g2D.translate(position.x, position.y);              // Translate to position
      g2D.scale(zoomX,zoomY);
      g2D.rotate(angle);                                  // Rotate about position
      g2D.setPaint(highlighted ? Color.magenta : color);  // Set the element color
      g2D.setStroke(new BasicStroke(lineWidth)) ;
      g2D.fillPolygon(p) ;
      g2D.draw(arrow3);
      // Draw the element
        g2D.setTransform(old);                              // Restore original transform     }
    private void writeObject(ObjectOutputStream out) throws IOException
         {     }         private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
         {     }
         GeneralPath arrow3;
    }
      

  2.   

    javax\swing\text\html\parser还是
    org\w3c\dom
      

  3.   

    Entity 是父类,关键是  p=new Polygon(xPoints,yPoints,3);arrow3.append(p,false);
    从新贴一下改后的代码:
     public class Arrow3 extends Entity{  Point UpEnd,DownEnd;
      Polygon p;
      public Arrow3(Point start, Point end, Color color,float lineWidth)
         {
           super(color,lineWidth);
           position = new Point(Math.min(start.x, end.x), Math.min(start.y, end.y));
           createPath(position,end);     }
         public java.awt.Rectangle getBounds()
         {
           return getBounds(arrow3.getBounds());     }     Point  RotatePoint( Point srcPoint, Point basePoint,
                                                       double dAngle)
         {// 求得源点srcPoint绕basePoint旋转dAngle角度后的点
                  Point p=new Point();
                 double cosv = Math.cos(dAngle) ; // cos value
                 double sinv = Math.sin(dAngle) ;
                 p.x =(int)(srcPoint.x * cosv - srcPoint.y * sinv +
                           (1.- cosv) * basePoint.x + basePoint.y * sinv);
                 p.y =(int)(sinv * srcPoint.x + cosv * srcPoint.y +
                           (1.- cosv) * basePoint.y - sinv * basePoint.x);
                 return p;
    }
          public  void createPath(Point start,Point end) {
            Point PointRotate=new Point();
         double dDist=Math.sqrt((end.x-start.x)*(end.x-start.x)+(end.y-start.y)*(end.y-start.y));
                   if (dDist<1.0) dDist=1.0;
                   double dRatio=14/dDist;
                   PointRotate.x=(int)((end.x-start.x)*dRatio+end.x);
                   PointRotate.y=(int)((end.y-start.y)*dRatio+end.y);
                   UpEnd=RotatePoint(PointRotate,end,-Math.PI*7/8);
                  DownEnd=RotatePoint(PointRotate,end,Math.PI*7/8);
            Point2D.Float  point=new Point2D.Float();
            arrow3=new GeneralPath();
            arrow3.moveTo(0,0) ;
            arrow3.lineTo(end.x-position.x,end.y-position.y) ;
             int[] xPoints=new int[3];
            int[] yPoints=new int[3];
             xPoints[0]=UpEnd.x-position.x;
             yPoints[0]=UpEnd.y-position.y;
             xPoints[1]=DownEnd.x-position.x;
             yPoints[1]=DownEnd.y-position.y;
             xPoints[2]=end.x-position.x;
             yPoints[2]=end.y-position.y;
             p=new Polygon(xPoints,yPoints,3);
             arrow3.append(p,false);      }
     public void modify(Point start, Point end)
         {
       createPath(position,end);
          }
    public void draw(Graphics2D g2D)
    {
     AffineTransform old = g2D.getTransform();           // Save the current transform
     g2D.translate(position.x, position.y);              // Translate to position
      g2D.scale(zoomX,zoomY);
      g2D.rotate(angle);                                  // Rotate about position
      g2D.setPaint(highlighted ? Color.magenta : color);  // Set the element color
      g2D.setStroke(new BasicStroke(lineWidth)) ;
      g2D.fillPolygon(p) ;
      g2D.draw(arrow3);
    // Draw the element
        g2D.setTransform(old);                              // Restore original transform     }
    private void writeObject(ObjectOutputStream out) throws IOException
         {
      PathIterator iterator = arrow3.getPathIterator(new AffineTransform());
                  Vector coords = new Vector();            // Stores coordinate objects
                  int maxCoordCount = 6;                   // Maximum coordinates for a segment
                  float[] temp = new float[maxCoordCount];            // Stores segment data
                  int result = iterator.currentSegment(temp);           // Get first segment
                  if(!(result == iterator.SEG_MOVETO))                  // ... should be moveTo
                    throw new IOException("No starting moveTo for curve");
                  iterator.next();
                  result=iterator.currentSegment(temp) ;
                  coords.add(new Float(temp[0])); ///////////////line to  End
                  coords.add(new Float(temp[1]));
                  iterator.next() ;
                  /////需要添加Polygon段,请帮忙
                  
         }
    private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
         {
      Vector coords=(Vector)in.readObject() ;
      arrow3=new GeneralPath();
      arrow3.moveTo(0,0) ;
     arrow3.lineTo(((Float)coords.get(0)).floatValue(),((Float)coords.get(1)).floatValue() ) ;//line to  End
     int[] xPoints=new int[3];
     int[] yPoints=new int[3];
     xPoints[0]=((Float)coords.get(0)).intValue()  ;
     yPoints[0]=((Float)coords.get(1)).intValue()  ;
     xPoints[1]=((Float)coords.get(2)).intValue()  ;
     yPoints[1]=((Float)coords.get(3)).intValue()  ;
     xPoints[2]=((Float)coords.get(4)).intValue()  ;
     yPoints[2]=((Float)coords.get(5)).intValue()  ;
     p=new Polygon(xPoints,yPoints,3);
             arrow3.append(p,false);     }
         GeneralPath arrow3;
    }