Example usage for java.awt.geom Rectangle2D.Float setRect

List of usage examples for java.awt.geom Rectangle2D.Float setRect

Introduction

In this page you can find the example usage for java.awt.geom Rectangle2D.Float setRect.

Prototype

public abstract void setRect(double x, double y, double w, double h);

Source Link

Document

Sets the location and size of this Rectangle2D to the specified double values.

Usage

From source file:GradientPane.java

public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    Point2D.Float p1 = new Point2D.Float(150.f, 75.f); // Gradient line start
    Point2D.Float p2 = new Point2D.Float(250.f, 75.f); // Gradient line end
    float width = 300;
    float height = 50;
    Rectangle2D.Float rect1 = new Rectangle2D.Float(p1.x - 100, p1.y - 25, width, height);
    GradientPaint g2 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY, false); // Acyclic
                                                                                       // gradient
    rect1.setRect(p1.x - 100, p1.y - 25, width, height);
    g2D.setPaint(g2); // Gradient color fill
    g2D.fill(rect1); // Fill the rectangle
    g2D.setPaint(Color.BLACK); // Outline in black
    g2D.draw(rect1); // Fill the rectangle
    g2D.draw(new Line2D.Float(p1, p2));
}

From source file:Main.java

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

    Point2D.Float p1 = new Point2D.Float(150.f, 75.f);
    Point2D.Float p2 = new Point2D.Float(250.f, 75.f);
    float width = 300;
    float height = 50;
    GradientPaint g1 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY);
    Rectangle2D.Float rect1 = new Rectangle2D.Float(p1.x - 100, p1.y - 25, width, height);
    g2D.setPaint(g1);/*from ww w. j  av  a2  s .  c o m*/
    g2D.fill(rect1);
    g2D.setPaint(Color.BLACK);
    g2D.draw(rect1);
    g2D.draw(new Line2D.Float(p1, p2));
    g2D.drawString("Cyclic Gradient Paint", p1.x - 100, p1.y - 50);
    g2D.drawString("p1", p1.x - 20, p1.y);
    g2D.drawString("p2", p2.x + 10, p2.y);

    p1.setLocation(150, 200);
    p2.setLocation(250, 200);
    GradientPaint g2 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY, false);
    rect1.setRect(p1.x - 100, p1.y - 25, width, height);
    g2D.setPaint(g2);
    g2D.fill(rect1);
    g2D.setPaint(Color.BLACK);
    g2D.draw(rect1);
    g2D.draw(new Line2D.Float(p1, p2));
    g2D.drawString("Acyclic Gradient Paint", p1.x - 100, p1.y - 50);
    g2D.drawString("p1", p1.x - 20, p1.y);
    g2D.drawString("p2", p2.x + 10, p2.y);
}

From source file:MainClass.java

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

    Point2D.Float p1 = new Point2D.Float(150.f, 75.f);
    Point2D.Float p2 = new Point2D.Float(250.f, 75.f);
    float width = 300;
    float height = 50;
    GradientPaint g1 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY, true);
    Rectangle2D.Float rect1 = new Rectangle2D.Float(p1.x - 100, p1.y - 25, width, height);
    g2D.setPaint(g1);/*from   w w  w.jav a 2  s . co  m*/
    g2D.fill(rect1);
    g2D.setPaint(Color.BLACK);
    g2D.draw(rect1);
    g2D.draw(new Line2D.Float(p1, p2));
    g2D.drawString("Cyclic Gradient Paint", p1.x - 100, p1.y - 50);
    g2D.drawString("p1", p1.x - 20, p1.y);
    g2D.drawString("p2", p2.x + 10, p2.y);

    p1.setLocation(150, 200);
    p2.setLocation(250, 200);
    GradientPaint g2 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY, false);
    rect1.setRect(p1.x - 100, p1.y - 25, width, height);
    g2D.setPaint(g2);
    g2D.fill(rect1);
    g2D.setPaint(Color.BLACK);
    g2D.draw(rect1);
    g2D.draw(new Line2D.Float(p1, p2));
    g2D.drawString("Acyclic Gradient Paint", p1.x - 100, p1.y - 50);
    g2D.drawString("p1", p1.x - 20, p1.y);
    g2D.drawString("p2", p2.x + 10, p2.y);
}