CS101 Project 6
Note new text in the "What you must do" section
In this lab you will
build the first
part of a one level graphical game. In this part you will create the
game board and have a colored ball bounce around the game board, making
sure that the ball never leaves the board.
The high level objectives of this lab are:
- Use a UML
diagram to help you begin writing your program from a given program
event driven programming that is not based on user intereaction (using
the javax.swing.Timer class)
What you must do:
You must write two classes, implementing the design in the UML diagram below. Your project will show a ball bouncing around the screen. A picture of my solution can be found below the UML diagram.
- Class Ball
- Constructor should set the ball color and do any other setup that needs to be done.
- setBoardSize should set the
_windowHeight and _windowWidth instance variables with the width and
height of the board respectively.
- paint should first calculate the new position of the ball and then paint the ball using the Graphics object that you are passed.
- Class GamePanel
- Constructor should implement
the has-a relationship and do any other setup (this class uses the
paintComponent method so make sure that it used the "extends JPanel"
syntax that we discussed in class. Also make sure to import
- actionPerformed should cause
the panel to repaint itself. You can ask java to force a repaint by
calling the method repaint() which is available to this class through
the "extends JPanel" syntactic magic.
- paintComponent should do the drawing of the ball in this method. (hint call paint on _ball) Also:
if you are seeing a long trail behind your ball, you will need to add
the following line as the *first* line in your paintComponent method:
When you submit this time, add a readme.txt file to your lab6 folder. The
readme should contain:
Once your readme is in place, submit as usual with the online
submission. Use your last and and the project number in your zip file
- Your name.
- A very brief summary of what you did, including any new methods you added and why you chose to implement things the way you did.
- Directions on how to run your program and anything unusual that I need to do to get it working properly.
- A list of any problems still in your code or anything that you didn't get done.