Hi There!

I'm Dan Schlegel, an Associate Professor in the Computer Science Department at SUNY Oswego

Assignment 3 – Pulsating Squares

Write a Java Swing application that displays pulsating squares:

  1. Write a Square class, where each square:
    • Has a (fixed) size
    • Has a (variable) solid color
    • Has a successor
    • Has any other methods needed by SquareList and/or PuslsatingSquareApp (see below).
    • Can display itself (using the Java Graphics class’s fillRect) relative to some origin, and then directs its successor (if one exists) to display itself centered within the current square by figuring out what its origin should be. The effect is something vaguely like this:
  2. Write a SquareList class that maintains a list of Squares in size-based order (largest/outermost first), and contains any other methods that might be helpful in this application.
  3. Write a class using Swing, PulsatingSquareApp, that maintains an initially empty SquareList and contains controls to:
    • Add a new Square with a randomly (or otherwise) chosen color and a randomly chosen size up to a maximum of 400 units — see Math.
    • Rotate: Find the color of the innermost square. Use it for the color of the outermost square, and from there change each successor’s color to its predecessor’s old color. For example, if a set of 3 existing squares were (1)red, (2)green, (3)blue, then after a rotate, they would be (1)blue, (2)red, (3) green.
    • Pulse: Rotate as many times as there are squares on the list. (Note: You will probably want to pause after each rotate using a Swing Timer or similar code.)

Note: To make this application easier to develop and test, you may wish to write the list of squares to the console.