Project 2

CS 178 - Fall 2004
Assigned: September 20, 2004
Due: Sunday, October 10, 2004 at 11:59pm
Created by the diabolical mind of Barry Wittman


Introduction

The purpose of this project is to further initiate you into the mystical world of Java applet creation. Not only will you make widgets, but in this project they will actually do things. Your group will be responsible for creating an applet with the same functionality as our sample applet. Doing so will require adding action listeners, keeping track of some internal data, and updating the display appropriately. No doubt you are wondering, "Could this finally be an applet with some practical purpose?"


The Task

Probably not. But judge for yourself. Your mission is to create an applet that will allow you to select a time zone in the United States, enter a time for it, select another time zone, and automatically generate the correct time in the second time zone. For practical reasons, we are limiting the project to just the U.S., but the principles could easily be extended to a map of world time zones. In terms of functionality, your applet must match ours exactly, though a minor graphical difference or two isn't a big deal. Don't forget to support 24-hour as well as 12-hour time formats, and always check the entered time to make sure that it is legal. The programming to figure out the correct remote time might take a little more cleverness than you expect, particularly when crossing from AM into PM or back.


The Hurdle

Unfortunately, there is an extra problem that you probably haven't considered. Wouldn't it be nice to be able to display each of the four American time zones as a picture that can be clicked on? Sure, and that's what the sample applet does. No doubt you are racing to your trusty Programming.Java textbook to find the method that will let you display a graphic on your favorite Java widget, the Button. But, you'll be looking for a long time. In fact, even if you go to your favorite website, java.sun.com, and look through every single method that the Button has, you'll never find it. It can't be done. The simplest way to make a button that displays an image is to use a widget called a JButton. This class is part of the Swing library, something that we aren't going to touch on until later in the semester. However, since you are all men and women of spunk and determination, we're sure that you can handle a JButton now. And, for those of you who are short of spunk and determination, all of the work of declaring the JButtons and setting up the images has been done for you in the skeleton code. For the rest of the work on this project, you should be able to treat them like regular Buttons. Adding action listeners and so on is done in exactly the same way.


What's Given

In case you missed it in the previous section, we are giving you some skeleton code which you can download here.

By the way, if you are trying to exactly match our sample applet, its size is 550x600 pixels.

Here, of course is the sample applet:

Note: The Choice box in the sample applet may not function properly in Mozilla and Firefox. Of course, the only two choices are "AM" and "PM".

And here is a list of the graphics files you'll need for your buttons:

All you need to do is make sure they are in the same directory as your .java files.


The Submission

The project should be turned in electronically by Sunday, October 10, 2004 at 11:59pm. In accordance with the Grading Policy, projects which are turned in more than 24 hours in advance of the deadline or at any time after the deadline will have their grades adjusted accordingly. You should turn in a single Java source file called TimeZone.java. Project submission should be done via CVS in the same way as Project 1. If you are having trouble submitting your files, talk to your TA for help.