Part 2:
Once you get the basic version
working, we would like you to jazz it up a bit. Here are the
extensions we would like you to make:
- Add labels (Text items) at the bottom of the picture showing
the number of correct and incorrect placements. This makes it
clearer when the student succeeds in placing the item correctly.
They should read something like "correct = nn", "incorrect =
mm". The value in the first Text item will be formed by
concatenating the string "correct =" with an integer instance
variable which keeps track of the number of correct answers. The
other is similar.
- Users should drag the items to the correct laundry basket
rather than just clicking on the basket. Recall from the examples
in class that you will need an instance variable to label the last
mouse position before the drag so you can determine how far to
drag the item. If the user presses the mouse button down outside
the laundry item, it should not increase the correct or the
incorrect counter.
- Assign the item a randomly generated color by randomly
choosing integers redNum, greenNum, and
blueNum between 0 and 255 for each of the red, blue, and
green components of the color. You can create a color from those
components by writing new
Color(redNum,greenNum,blueNum)).
Now define criteria for determining where each color
should go. The simplest criterion is based on the sum of the
three color components. If the sum of the component numbers is
less than 230, decide it is dark, if it is greater than 600,
decide it is white. Otherwise it is colored. This rule isn't
perfect, so after you get the
program working you might want to experiment with other criteria.
We will let you figure out most of the details of how to add the
features for the more advanced versions. One piece of advice is that
for the second enhancement you will be dropping the
onMouseClick method in favor of using the three methods:
- onMousePress - for when the user first clicks on
the item - though remember that they might miss.
- onMouseDrag - to do the actual dragging.
- onMouseRelease - check to see if they've dropped
it in the right place when the mouse is released.