import java.awt.image.BufferedImage; import java.awt.Graphics2D; import java.awt.Color; import java.io.File; import javax.imageio.ImageIO; import java.io.IOException; import java.awt.Rectangle; /** A class for an ItalianFlag */ public class ItalianFlag { private BufferedImage flag; public ItalianFlag(int width, int height) { // This creates a new image object that we can draw on, including drawing fills // The TYPE_INT_ARGB just means that we have Red, Green, Blue and "Alpha" // 'Alpha' is a way of making this transparent, or partially transparent. flag = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = flag.createGraphics(); Rectangle outline = new Rectangle(0,0,width,height); Rectangle left = new Rectangle(0,0,width/3,height); Rectangle middle = new Rectangle((int) (width * (1.0/3.0)),0, (int) (width/3.0), height); Rectangle right = new Rectangle((int) (width* (2.0/3.0)) ,0, (int) (width/3.0),height); g2.setColor(Color.BLACK); g2.draw(outline); g2.setColor(Color.GREEN); g2.fill(left); g2.setColor(Color.WHITE); g2.fill(middle); g2.setColor(Color.RED); g2.fill(right); } public BufferedImage getImage() { return this.flag; } }