Assignment 1
COMP 106



The main project in this course will be based on the classic game of Battleship. If you are not familiar with the game, feel free to plug it into your search engine of choice. You may even want to play a couple of games just to remind yourself of the rules.

Gradually, over the course of the semester we will build a working version of Battleship. First the GUI framework, then the controls, then the game, etc. Eventually, you'll be able to play a working game of Battleship, and even include a few bonus features along the way. Keep this in mind as you move forward with your programming (but be careful not to jump ahead. We will introduce a few twists and turns that are very different from the traditional version you are familiar with).

For this assignment, you will be playing with some basic Java Swing components and building a visual framework for the remainder of your semester. You should use the Swing graphics package to create a window that contains the following elements your program will eventually need:

Drawing Area

This is the section of your window where the main action occurs. For this assignment, just create a drawing area widget that will consume a significant part of your main window. (This object can be similar to the MyCanvas object used in lecture examples and subclass JComponent.) Inside this drawing area, draw some simple shapes. Maybe a smiley face. Maybe a basic snowman. Maybe complex blueprints of the architecture of your house =)

Control Panel

The main project will eventually be customizable, using widgets in a control panel. For this assignment, create a control panel on the bottom of the screen, perhaps as a subclass of JPanel. Add at least one widget to the control panel. For now, interacting with these widgets (pressing a button, selecting an item for a list, etc) should just cause a message to be printed to the command line. For example, clicking Button1 might result in "Button1 was clicked" to be printed to the command line. Feel free to be creative, but have some sort of correlation between the button name and the output. (A button titled "Start Large Hadron Collider" could print out "The world may or may not be crushed by a black hole".) For this assignment, you can use any layout for the widgets (FlowLayout is the default). Don't worry yet about how the widgets are positioned within the control panel or their spacing.

State Panel

This area will display the state of your project, such as scores, timer, or other status information. For this assignment, just create a separate panel that will consume a relatively small part of your window. Later, you will put some widgets that are more informative (number of boats left, shooting percentage, etc.).

Other Considerations

Your program will create the main window, create the widgets and lay them out, create any other data objects you need, and install listeners for your widgets as needed. Then, it lets the Java window system take over, providing the main loop.

To set the size of your canvas in a FlowLayout, you will probably need to use: setPreferredSize (new Dimension (width, height)) rather than: setSize (width, height). You can also look ahead at the Layout.java example for more sophisticated ways to lay out your window.


Java Software

You should use Java and Swing, we are using version 1.6.0 in class demos, most older versions should be fine too.

You can download the Java software from the link on the course home page and run on your own machine. Or you can run it on the suns from the unix command line. You can also use the machines in the Windows NT lab, where Java should should already be installed. Your code should be portable among all of these platforms, but if there are any incompatibilities, your code must ultimately compile and run on the TA's machine, which will be a Windows PC. We will use this first assignment to discover any incompatibilities we didn't know about.

Note: If you are having trouble running java on your PC, make sure the CLASSPATH environment variable is not set. Some other program installations may have set it automatically. In Windows, the environment variables are in the System control panel under Advanced / Environment Variables. You may also want to add the directory where the javac program lives (typically something like C:\Program Files\Java\jdk1.6.0_07\bin to your PATH environment variable. You can add also this directory to your PATH variable temporarily, just in a single window, by typing set PATH=%PATH%;C:\...etc... on the command line.


Programming Practices

For this assignment focus on writing readable code. In short this means:

You should follow these general Java programming practices:

And, finally, for uniformity please name your Java class that has your main program in it Main, in file Main.java

Coding style will constitute a increasingly large percentage of your grade as the semester progresses.


How to Submit Your Programs

Follow the procedure here to submit your assignment.

T.A.

See the course home page for office hours and contact info.

Grading

Drawing area with a shape/drawing 2 points
Control panel with at least one widget. 2 points
Interacting with control panel widget prints out a message to the command line 2 points
State panel 1.5 points
Follows all guidelines in Programming Practices section above 1 point
Adds something more, does something new, or significantly surpasses any of the preceding criteria (e.g., multiple widgets, draw stuff out in the state panel). Don't forget this part! 1.5 points, see below

Creating an excellent, nontrivial software application requires creativity beyond what your customers, or professor, can explicitly mandate. In general, great software satisfies a set of general requirements or requests, and then adds something beyond that. Grading for the assignments will reflect this fact. Satisfying exactly the bare minimum for each assignment will merit a grade of approximately 75% or 85%, depending on the specific assignment (15% for this assignment, as listed above). The remaining points will be awarded for additional work that adds the special something. This is not necessarily easy to do. You will be both the software designer and the software developer in this course. It's not just the implementation that is important, but also the design of the application. If you do this, include a brief description in your readme file, as noted in the submission instructions.