package chapter2; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import javax.swing.JComponent; //components are things we can draw with, this tells the computer I want my class to be drawable too public class RectangleComponent extends JComponent { private Rectangle rectangle; //the box we made private Color color; //construct the RectangleComponent public RectangleComponent(Rectangle box, Color whatColor) { rectangle = box; color = whatColor; } //necessary to draw public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; //necessary due to changes in Java g2.setColor(color); //what color should I draw in g2.draw(rectangle); //draw the box that we made } }