Java Reference
In-Depth Information
΢΢΢GExercise P9.22. Change the RectangleComponent for the
animation program in Section 9.9 so that the rectangle bounces off the
edges of the component rather than simply moving outside.
΢΢GExercise P9.23. Write a program that animates a car so that it moves
across a frame.
΢΢΢GExercise P9.24. Write a program that animates two cars moving across
a frame in opposite directions (but at different heights so that they
don't collide.)
΢΢GExercise P9.25. Change the RectangleComponent for the mouse
listener program in Section 9.10 so that a new rectangle is added to the
component whenever the mouse is clicked. Hint: Keep an
ArrayList<Rectangle> and draw all rectangles in the
paint-Component method.
434
435
΢΢GExercise P9.26. Write a program that demonstrates the growth of a roach
population. Start with two roaches and double the number of roaches
with each button click.
Additional programming exercises are available in WileyPLUS.
PROGRAMMING PROJECTS
΢΢΢ Project 9.1. Design an interface MoveableShape that can be used as a
generic mechanism for animating a shape. A moveable shape must have
two methods: move and draw . Write a generic AnimationPanel
that paints and moves any MoveableShape (or array list of
MoveableShape objects if you covered Chapter 7 ). Supply moveable
rectangle and car shapes.
΢΢΢ Project 9.2. Your task is to design a general program for managing
board games with two players. Your program should be flexible enough
to handle games such as tic-tac-toe, chess, or the Game of Nim of Project
6.2.
Search WWH ::




Custom Search