Due at 5:00pm, Monday, February 25th, 2008, by email submission only.
This assignment explores the following topics related to GUI output:
We provide you with a lot of existing code for this assignment. You can get it all at once here:
java -jar ps2-provided.jarto see the BoardViewTester window pop up, displaying a checkerboard (right).
The board model actually has pieces on it, but you won't see them until you've implemented the pieces display. You can unpack ps2-provided.jar
jar xf ps2-provided.jarto find the source code and Javadoc documentation. Documentation for all classes is also available on the web. If necessary, you can change these classes as you see fit.
This problem set, and future problem sets, require Java 1.5 (or later). If you use Eclipse, you'll need Eclipse 3.1 or later for full support for the JDK. Both are installed on Athena.
Fill in the skeleton of StrokeBoardView so that it displays all the checkers on the board using strokes drawn on Graphics. At a minimum, red checkers should be red circles and black checkers should be black circles. Feel free to make your checkers look better, if you like, but you may want to defer this until you've done all the problems.
Your StrokeBoardView must update when the board changes so that it displays the current state of the board at all times. You can test this in BoardViewTester by clicking on the buttons, which produce various board configurations.
If you need help understanding the Swing painting model, you may want to look at Sun's article Painting in AWT and Swing. Particularly useful is the summary of Swing painting guidelines at the end of the article.
Fill in the skeleton of PixelBoardView so that it displays checkers using pixel images. Two pictures are provided for you in the jar file (red-piece.png and black-piece.png, found in the ui directory), but you can replace them with different pictures if you prefer. These image files should be loaded as resources, not as files.
Like StrokeBoardView, your PixelBoardView must update when the board changes, so that it displays the current state of the board at all times.
Images in Java can sometimes be a pain, because Java is designed to allow loading images lazily from a network connection. You can avoid these headaches by using javax.swing.ImageIcon to load the image as a Swing icon, and then call getImage() to get an Image object that you can actually draw with.
Fill in the skeleton of ComponentBoardView so that each checker is represented by its own JComponent object. The skeleton code includes an inner class CheckerComponent that represents a single checker. You'll have to fill in code to make this component draw itself, which it can do with either strokes or a pixel image. You'll also have to write code in ComponentBoardView for creating and managing CheckerComponent objects.
Like the other views, your ComponentBoardView must update when the board changes, so that it displays the current state of the board at all times. Warning: Swing has a bug (which Sun stubbornly refuses to fix) such that a container with no layout manager fails to repaint when a component is removed from it. When you remove a checker component, you'll have to call repaint manually.
Answer the following questions in readme.txt.
Package your completed assignment as a jar file, as described in PS1. Here's a checklist of things you should confirm before you hand in:
java -jar yourfile.jar
Submit your solution by email (with all required jar files attached) to 6831handin@csail.mit.edu and include PS2 in the subject line.