[Original] Code Example: Draw a beautiful arrow

xiaoxiao2021-03-06  73

[Original] painting a beautiful arrow

. / ** * @ (#) ArraowLinePanel.java * * Copyright 2004 Opensource Develop Team All rights reserved * /// packagepakcage com.opensource.arrow;. // import classesimport java.awt *;. Import java.swing *. Import java.awt.geom. *: / ** * Painted an arrow in Panel * * @Author odt * @version 1.0 22/04/2004 * @see jpanel * @since 1.3 * / class arrowlinePanel Extends jPanel {/ / confirm the line position Line2D line = new Line2D.Float (100f, 100f, 300f, 300f); ArrowLinePanel () {setBackground (Color.white);} public void paintComponent (Graphics g) {super.paintComponent (g); Graphics2D G2D = (graphics2d) g; g2d.setcolor; g2d.draw (line); // Draw line without arrow. Double x1 = line.getx1 (); double x2 = line.getx2 (); double y1 = line.gety1 (); double y2 = line.gety2 (); // compute the line's length double lonning = math.sqrt (x1-x2) * (x1-x2) (Y1-Y2) * (Y1- Y2)); g2d.translate (x1 , y1); // compute the Angle Between Line and x Axis. Double Roate = Math.atan ((Y2-Y1) / (x2-x1)); // Draw arrow generalpath path = new generalpath (); path.moveto (Float), 0); Path.Lineto ((Float) Length - 10, -5); Path.Lineto ((Float) Length - 7, 0); Path.Lineto ((Float) Length - 10, 5 ); Path.lineto ((float), 0); path.closepath (); area area = new area (path); g2d.fill (area);}}

转载请注明原文地址:https://www.9cbs.com/read-121076.html

New Post(0)