CS202 - Transition to Java: Assignment 2 CS202 Site Index - Main - Information - Registration - Announcements - Lectures - Assignments - Submit - View - Reference - Passwords CS202 - Fall 1999 Transition to Java Assignment 2 Updates Solution available: BoardView.java Due date Wednesday, 15 September 1999 at 12:20pm. Advice Start today. This is a long assignment. Make use of office hours and the newsgroup. Ask for help, clarification. Check the web site and newsgroup frequently for updates Don't copy. The consequences are severe. Introduction to Swing In this assignment we are going to create a user interface for the game. User interface design is a complex, intricate issue that has undergone much study. Our user interface will be very simple. It has two goals: Display our data structures, such as the board, to the user Allow the user to activate certain game operations Since Java was released it has developed greatly in the area of user interfaces. All standard, portable user interfaces are built on top of the Abstract Windowing Toolkit (AWT), whose classes are to be found in the java.awt package. In JDK 1.1 the AWT was considerably improved from the original release, and made much use of the new inner classes language capability. Although, in principle, this was sufficient to build any application, people soon discovered a lack of components such as checkboxes, menus, drop-down lists, buttons and others commonly found in graphical applications. Sun answered this need by implementing Swing (now called Java Foundation Classes, or JFC for short). Swing is a set of classes that create component objects using the AWT facilities and is 100% pure Java code. Swing actually comes as part of the JDK 1.2, but we will be using the JDK 1.1.8 with the Swing 1.1 add-on. Do NOT use JDK 1.2 for this assignment. To install Swing you just need to download the classes and add them to your CLASSPATH. It can be downloaded in tar or zip formats or with Solaris or Windows installers from: Sun's JFC page. Alternatively, all you really need are the classes, stored in a file called swingall.jar that I provide locally. Get this file onto your system either from Sun (extracting file, or installing) or from the course server and save it in some location, say c:\java\swingall.jar. Then set you class path to look like: CLASSPATH=.;c:\java\lib\classes.zip;c:\java\swingall.jar. Swing and the AWT are big and complicated. You will not be able to learn them and do the assignment in the last moments. Start early! Sun provides lots of examples and tutorials about the AWT and Swing (see the reference page). You are expected to use these resources to discover the classes you need, what they can do, and how they are to be used. Some examples will be discussed in class to get you started. User interface Piece and WildcardPiece have been defined. The versions provided do all that was requested in A1 and more. Read the source code and comments to understand the added functionality pertaining to Piece images. You will need to use these images in the user interface. Do not concern yourself with how these images are created, and just use the appropriate accessor functions to retrieve them. You must have the IMAGES.bin file in the same directory as the .class files for this to work, since the images are stored in this file as a compressed object stream and are loaded the first time the Piece class is referenced. Also provided, is a simplified version of the Board class that will appear in the final game. The final version will allow us to find vertical and horizontal words crossing a given square, evaluate the score of a play, etc... The current version just stores the Pieces on the board, and provides methods to put new pieces on, take pieces off and find out what piece is currently on a given square. The class also statically stores the specifics of a Javlle board. Read and understand this class. Just so that you know where we are headed, this is what the result of this assignment should look like... That, in a nutshell, is your task. (This image was taken from Linux running the KDE window manager, so the outer outline of your frame and fonts may be slightly different on your system). There are many ways this can be done, and I will outline below the method I recommend you use. However, you are free to do as you will, as long as the user interface shortly defined is supported and the design is logical and clean. The program will be tested via a driver class called a2test. Your implementation should function if one types java a2test at the command line. Start by creating the static method createPlayerWindow. Create a simple JFrame and title it. Add a window listener that responds to close requests, and performs a System.exit. We can now start laying out components on the content pane. Add the button. Add the letters at the top, as a label. Give the button an action listener that responds to clicks and writes "Go" to the System.out. Now we are going to create the board, a special type of JComponent, that displays the board and the pieces on it. It will Observe changes of the board object and update itself, but for now just write out an empty update function to keep the compiler happy. Lay out a grid of Board.SIZE x Board.SIZE buttons and give each on the right color and icon (if it contains a piece). Write separate methods for setting the colors and icons. Write the body of the update method to update the view. And we are almost done... Just make each square cycle to the next state each time it is clicked. The sequence should be empty, a, b, c, ... , y, z, empty... That's it. It's very basic, and Javlle needs more work. But congratulations on your very first Java user interface! Submission Before the assignment deadline you are expected to sumbit one file into your A2 directory: BoardView.java Make sure your program can used via the supplied driver code. Attachments swingall.jar a2test.java Piece.java WildcardPiece.java Board.java IMAGES.bin Good luck. Copyright 1999, Rimon Barr, Cornell University RB f99-cs202: a.2.html (6487)