Example usage for java.awt Graphics2D draw

List of usage examples for java.awt Graphics2D draw

Introduction

In this page you can find the example usage for java.awt Graphics2D draw.

Prototype

public abstract void draw(Shape s);

Source Link

Document

Strokes the outline of a Shape using the settings of the current Graphics2D context.

Usage

From source file:Main.java

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

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.black);//w  ww  .ja  v  a  2  s  . com
    g2.draw(new Rectangle2D.Float(10, 20, 30, 40));

    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);

    g2.setPaint(Color.red);
    g2.draw(new Rectangle2D.Float(10, 20, 30, 40));
}

From source file:Main.java

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

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.black);// www .j  av  a  2 s  .  c  o m
    g2.draw(new Rectangle2D.Float(10, 20, 30, 40));

    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.setTransform(at);

    g2.setPaint(Color.red);
    g2.draw(new Rectangle2D.Float(10, 20, 30, 40));
}

From source file:BasicDraw.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    float strokeThickness = 5.0f;

    BasicStroke stroke = new BasicStroke(strokeThickness);
    g2d.setStroke(stroke);//  ww w  .  ja  v a  2s.co m

    g2d.draw(new Rectangle(20, 20, 200, 200));

}

From source file:MainClass.java

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);/*w  w  w  .  jav  a  2s  .c om*/
    g2D.draw(quadCurve);
    g2D.draw(cubicCurve);
}

From source file:MainClass.java

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

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.black);/* www .  j av  a2s  .c  o  m*/
    g2.draw(shape);
}

From source file:BasicStrokeDemo.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke(3.0f));
    g2.setPaint(Color.blue);/*  w ww .j av  a2  s  .  c  o m*/

    Rectangle r = new Rectangle(5, 5, 200, 200);

    g2.draw(r);
}

From source file:ThickStrokeDemo.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke(8.0f));
    g2.setPaint(Color.blue);// w w  w.  ja v a 2s  . c om

    Rectangle r = new Rectangle(5, 5, 200, 200);

    g2.draw(r);
}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.setToTranslation(Math.PI / 6, Math.PI / 6);

    g2.setTransform(at);/* ww  w  .ja  v a  2s .c  om*/
    g2.draw(shape);

}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.transform(new Point(1, 2), new Point(2, 3));

    g2.setTransform(at);/* w  w  w  .  j ava2 s .c  o m*/
    g2.draw(shape);

}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.setTransform(AffineTransform.getRotateInstance(0.5));

    g2.setTransform(at);/*from w  ww  .  jav a  2  s  .  c  o m*/
    g2.draw(shape);

}