Click Boxes Lab
This Lab is a colorful way to practice how to search and remove things in an ArrayList. It is a perfect job for the while loop, because the size of the ArrayList is changing. You may wish to re-read Chapter 11 section 5 (page 325) about this topic.
You can see how it is supposed to work with this jar file: ClickBoxes.jar
You will need the Box class which has some static Arrays and a static method about the color palette. Box.java
Your job is to complete the remove
method of the ClickBoxes class. You will need to to go through the ArrayList called boxes
and look to see if it matches the color you care removing. If it does, remove it from boxes
, If it doesn't match, look for the next. Here is the starter code:
ClickBoxes.java
What else?
- In the
Box
class, add a String field calledlabel
- In the
Box
class, add asetLabel
method to have client classes change the contents oflabel
- In the
Box
class, change thedraw
method so it draws the label. The syntax of the graphics method that will do it isdrawString( String s, int x, int y)
. - In the
ClickBoxes
' class alter thepaintComponent
method that changes the label of each box in theboxes
ArrayList so that it it shows its order in the ArrayList.