fill Rect - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

fill Rect

Demo Code


import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.awt.image.DirectColorModel;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Main{
    public static void fillRect(Graphics g, Rectangle rec) {
        g.fillRect((int) Math.round(rec.x), (int) Math.round(rec.y),
                (int) Math.round(rec.width), (int) Math.round(rec.height));
    }//w w  w .j  a v a2 s  .  c o  m
    public static void fillRect(Graphics g, Rectangle rec, Color color) {
        final Color oldColor = g.getColor();
        g.setColor(color);

        DrawUtil.fillRect(g, rec);

        g.setColor(oldColor);
    }
}

Related Tutorials