Example usage for java.awt.geom Ellipse2D setFrame

List of usage examples for java.awt.geom Ellipse2D setFrame

Introduction

In this page you can find the example usage for java.awt.geom Ellipse2D setFrame.

Prototype

public void setFrame(Rectangle2D r) 

Source Link

Document

Sets the framing rectangle of this Shape to be the specified Rectangle2D .

Usage

From source file:FillTest.java

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

    // draw a rectangle

    double leftX = 100;
    double topY = 100;
    double width = 200;
    double height = 150;

    Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height);
    g2.setPaint(Color.RED);/*from w  ww.  java2s .  c o  m*/
    g2.fill(rect);

    // draw the enclosed ellipse

    Ellipse2D ellipse = new Ellipse2D.Double();
    ellipse.setFrame(rect);
    g2.setPaint(new Color(0, 128, 128)); // a dull blue-green
    g2.fill(ellipse);
}

From source file:DrawTest.java

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

    // draw a rectangle

    double leftX = 100;
    double topY = 100;
    double width = 200;
    double height = 150;

    Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height);
    g2.draw(rect);// www. ja  va 2  s  .  c o m

    // draw the enclosed ellipse

    Ellipse2D ellipse = new Ellipse2D.Double();
    ellipse.setFrame(rect);
    g2.draw(ellipse);

    // draw a diagonal line

    g2.draw(new Line2D.Double(leftX, topY, leftX + width, topY + height));

    // draw a circle with the same center

    double centerX = rect.getCenterX();
    double centerY = rect.getCenterY();
    double radius = 150;

    Ellipse2D circle = new Ellipse2D.Double();
    circle.setFrameFromCenter(centerX, centerY, centerX + radius, centerY + radius);
    g2.draw(circle);
}