new Line2D.Double(double X1, double Y1, double X2, double Y2) : Line2D « java.awt.geom « Java by API






new Line2D.Double(double X1, double Y1, double X2, double Y2)

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class MainClass extends JPanel {

  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    int w = getSize().width - 1;
    int h = getSize().height - 1;

    for (int i = 0; i < 12; i++) {
      double angle = Math.PI / 2 - i * Math.PI / 6;
      double x = Math.cos(angle);
      double y = Math.sin(angle);

      Line2D l = new Line2D.Double(100 + 55.0 * x, 100 - 55.0 * y, 100 + 65.0 * x, 100 - 65.0 * y);

      g2.draw(l);
    }
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new MainClass());

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200, 200);
    frame.setVisible(true);
  }
}
           
       








Related examples in the same category