/* * This is a class that draws a recursive squares. Fill in the method * drawSquares. * * Laura Toma, csci 210 */ import javax.swing.*; import java.awt.*; public class Squares extends JFrame { public static final int WINDOW_SIZE = 500; public static final int THRESHOLD = 40; //the upper-left corner of the first square and the side of the square public static int ul_x, ul_y, side; public Squares() { super("Squares"); setSize(WINDOW_SIZE, WINDOW_SIZE); //set initial square coordinates based on window size ul_x = (int)getSize().getWidth()/3; ul_y = ul_x; //set initial square side side = ((int)getSize().getWidth() - 2*ul_x); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void paint(Graphics g) { //clear the canvas and draw all ancestors super.paint(g); //draw the recursive squares drawSquares(ul_x, ul_y, side); } //draw recursivey a square with the upper left corner at (ul_x, ul_y) //and given side public void drawSquares(int ul_x, int ul_y, int side) { //termination condition: if the square is smaller than THRESHOLD stop if (side < THRESHOLD) return; //else draw the current triangle Graphics g = getGraphics(); g.setColor(Color.RED); //FILL IN YOUR CODE } public static void main(String[] args) { Squares sq = new Squares(); } }