|
Lab Practical - Dot Sorter |
|
| Sample Program | |
|
Solution: ColorSorter.java |
|
| Description | |
| In this program a
colored dot must be dragged onto the colored rectangle. Dark colors will
cause the rectangle to change color. The colored dot will change color
after every turn. Dark colors will be defined as any color where the sum of the RGB triple for all three components is less than or equal to 250. The RGB triple (0,0,0) is black and the RGB triple (255, 255, 255) is white. RGB stands for red, green, and blue. Several Color class methods allow you to examine each component of any given Color. These methods are: double getRed() double getBlue() double getGreen() Hint: FilledOvals and FilledRects have a method called getColor() that returns the Color of the object. |
|
| Specifications | |
| The dot The dot is a filled oval. It should be created at location 20, 75 with diameter 30. It should be assigned a random color using an RGB triple. The dark square The dark square should initially be black. It should be created at location 100, 75 with width and height 60. The canvas The canvas background should be set to the color represented by the RGB triple (200,200,200). The message A text message stating, “Drag the dot onto the square” should be located at (10,10). Dragging the dot The user should be able to drag the dot. If the dot is dragged onto the dark square and released, then the dark square’s color should be set to the dot’s color if and only if the dot’s color is considered dark by the specification described earlier in this assignment. When a dot is released two things should always happen. The dot should return to the location (20,75). The dot should change color to a new random RGB triple. |
|