import java.util.ArrayList; import uwcse.graphics.*; import java.awt.Color; /** * In a graphics window, place at random location a square when a key * is pressed on the keyboard. Delete that square if it is clicked with * the mouse. Keep track of the squares with an ArrayList */ public class ArrayListExample extends GWindowEventAdapter { // Keep the list of squares in an ArrayList private ArrayList squareList; // The graphics window private GWindow window; // length of the side of the squares private int side = 20; /** * Initialize the graphics window and the list of squares */ public ArrayListExample() // complete { // Create the graphics window window = new GWindow("Array list example",400,400); window.setExitOnClose(); // Send all of the events to this ArrayListExample window.addEventHandler(this); // Create the square list (initially empty) squareList = new ArrayList(); } /** * A key has been pressed. Create a square at a random location. */ public void keyPressed(GWindowEvent e) { // Center of the square (random point) // Color of the square (random) // Create the square and add it to the window and the square list // Show it } /** * Mouse click on the window. If it is on a square, erase that square */ public void mousePressed(GWindowEvent e) { // Iterate over the squares (from the last one to the first one) // Is the click on element i of the list? } }