Java by API/java.awt.geom/QuadCurve2D — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 14:39, 31 мая 2010

new QuadCurve2D.Double(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)

 
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.CubicCurve2D;
import java.awt.geom.Point2D;
import java.awt.geom.QuadCurve2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainClass extends JPanel {
  public MainClass() {
  }
  public void paint(Graphics g) {
    Point2D.Double startQ = new Point2D.Double(50, 75); // Start point
    Point2D.Double endQ = new Point2D.Double(150, 75); // End point
    Point2D.Double control = new Point2D.Double(80, 25); // Control point
    // Points for cubic curve
    Point2D.Double startC = new Point2D.Double(50, 150); // Start point
    Point2D.Double endC = new Point2D.Double(150, 150); // End point
    Point2D.Double controlStart = new Point2D.Double(80, 100); // 1st control
                                                                // point
    Point2D.Double controlEnd = new Point2D.Double(160, 100); // 2nd control
                                                              // point
    QuadCurve2D.Double quadCurve; // Quadratic curve
    CubicCurve2D.Double cubicCurve; // Cubic curve
    quadCurve = new QuadCurve2D.Double( // Create quadratic curve
        startQ.x, startQ.y, // Segment start point
        control.x, control.y, // Control point
        endQ.x, endQ.y); // Segment end point
    cubicCurve = new CubicCurve2D.Double( // Create cubic curve
        startC.x, startC.y, // Segment start point
        controlStart.x, controlStart.y, // Control point for start
        controlEnd.x, controlEnd.y, // Control point for end
        endC.x, endC.y); // Segment end point
    Graphics2D g2D = (Graphics2D) g; // Get a 2D device context
    // Draw the curves
    g2D.setPaint(Color.BLUE);
    g2D.draw(quadCurve);
    g2D.draw(cubicCurve);
  }
  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);
  }
}





QuadCurve2D.Float.Float(float x1, float y1, float ctrlx, float ctrly, float x2, float y2)

  
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.QuadCurve2D;
public class Main extends Frame {
  public static void main(String[] args) {
    (new Main()).setVisible(true);
  }
  public Main() {
    super("Shape Sampler");
    setSize(400, 550);
  }
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    QuadCurve2D quadcurve = new QuadCurve2D.Float(50, 300, 320, 300, 350, 400);
    g2d.draw(quadcurve);
  }
}