Example usage for java.awt Graphics2D fillRect

List of usage examples for java.awt Graphics2D fillRect

Introduction

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

Prototype

public abstract void fillRect(int x, int y, int width, int height);

Source Link

Document

Fills the specified rectangle.

Usage

From source file:Main.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true);

    System.out.println(gp1.isCyclic());
    g2d.setPaint(gp1);//ww w  .j  a  v a  2 s  .  c om
    g2d.fillRect(20, 20, 300, 40);

}

From source file:Main.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true);

    System.out.println(gp1.getColor2());
    g2d.setPaint(gp1);/*www  .jav  a  2s. c  o  m*/
    g2d.fillRect(20, 20, 300, 40);

}

From source file:Main.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true);

    System.out.println(gp1.getColor1());
    g2d.setPaint(gp1);// w ww. j  ava 2  s. co  m
    g2d.fillRect(20, 20, 300, 40);

}

From source file:Main.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true);

    System.out.println(gp1.getPoint2());
    g2d.setPaint(gp1);/*from ww  w.ja va2  s. c  o m*/
    g2d.fillRect(20, 20, 300, 40);

}

From source file:Main.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true);

    System.out.println(gp1.getPoint1());
    g2d.setPaint(gp1);//w  w  w.j av  a  2  s.c  o m
    g2d.fillRect(20, 20, 300, 40);

}

From source file:Main.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true);

    System.out.println(gp1.getTransparency());
    g2d.setPaint(gp1);/* w w w . ja v a2 s .  c  o  m*/
    g2d.fillRect(20, 20, 300, 40);

}

From source file:RotationAboutCenter.java

protected void paintComponent(Graphics g) {
    Graphics2D g2d;
    g2d = (Graphics2D) g.create();

    // Erase background to white
    g2d.setColor(Color.WHITE);/*from   ww  w. ja  v a2 s .c  o  m*/
    g2d.fillRect(0, 0, getWidth(), getHeight());

    // base rectangle
    g2d.setColor(Color.GRAY.brighter());
    g2d.fillRect(50, 50, 50, 50);

    // rotated 45 degrees around origin
    g2d.rotate(Math.toRadians(45));
    g2d.setColor(Color.GRAY.darker());
    g2d.fillRect(50, 50, 50, 50);

    // rotated 45 degrees about center of rect
    g2d = (Graphics2D) g.create();
    g2d.rotate(Math.toRadians(45), 75, 75);
    g2d.setColor(Color.BLACK);
    g2d.fillRect(50, 50, 50, 50);

    // done with g2d, dispose it
    g2d.dispose();
}

From source file:ChartServlet.java

/** Draw a Graphical Chart in response to a user request */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

    response.setContentType("image/jpeg");

    // Create an Image
    BufferedImage img = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB);

    // Get the Image's Graphics, and draw.
    Graphics2D g = img.createGraphics();

    // In real life this would call some charting software...
    g.setColor(Color.white);//  ww  w  .j  av a 2s  . c  o  m
    g.fillRect(0, 0, W, H);
    g.setColor(Color.green);
    g.fillOval(100, 75, 50, 50);

    // Write the output
    OutputStream os = response.getOutputStream();
    ImageOutputStream ios = ImageIO.createImageOutputStream(os);

    if (!ImageIO.write(img, "jpeg", ios)) {
        log("Boo hoo, failed to write JPEG");
    }
    ios.close();
    os.close();
}

From source file:maltcms.ui.fileHandles.serialized.SeriesPaintComboBoxRenderer.java

private BufferedImage createColorImage(Paint p) {
    BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = bi.createGraphics();
    g2.setPaint(p);//from www  .  j  av  a2  s .  c o m
    g2.fillRect(0, 0, bi.getWidth(), bi.getHeight());
    return bi;
}

From source file:Main.java

public void paintImage() {
    Graphics2D g = createGraphics();
    if (frame == frameGradient.length - 1)
        frame = 0;//from   w ww  .  ja  v a  2  s .c o  m
    else
        frame++;
    g.setPaint(frameGradient[frame]);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.dispose();
}