CSci 1211 Problem set 10. Due Monday, April 19th at 5pm
Project Assignment, Part 2 (30 points each person)
In this problem st you are asked to set up the graphical user
interface for the battleship game. You don't need to write the event
listeners (yet), but it's a good idea to keep the event listeners in
mind as you are writing the code. In the end of this assignment the
program should look just like the real game, but one can't play it
yet.
Here are some preliminary demo classes. These classes don't have the
full functionality, but give a pretty good idea about the Graphical
User Interface of the game. You might want to choose different colors
and fonts. Note that you don't need to implement any of the behavior
(that will be done in the third part of the assignment).
Warning: the classes may produce occasional
test-printing.
Your task is to re-write the Game class from the previous assignment
(you amy call it differently if you prefer) to create a graphical
interface for the battleship program. You may, if you'd like, create
an interface which is somewhat different from the demo above. However,
if you are using different components and/or layouts, please keep in
mind that I might know less about them than about those used in the
demo, so I might not be able to give you that much help on getting
things to work.
Some helpful hints for this assignment:
- The top-level layout is BorderLayout
- The east and west components are JPanels
with a 11-by-11 GridLayout.
The top-most row and the left-most column are Jlabels and the
battleship squares are JButtons.
- The center component is a JPanel with a GRidLayout, a JLabel on
top, one JRadioButton
per ship, and a JButton in the bottom to position the ship. All
JRadioButtons belong to the same ButtonGroup,
this way only one can be selected at any given time.
- To set the size of a component, use setPreferredSize() method, NOT
setSize(), since these sizes are controlled by the layout. Warning:
this may take a while to get to work.
- In order to easily handle events, make all the
components and all the information about the other elements (boards,
etc.) global. This way they will be accessible by all methods. Make
sure to initialize them correctly (a common mistake is to initialize
a local variable with the same name instead).
This page is a part of the course CSci
1211 at UMM.