Lab 4: Interfaces and Swing


Your goal this week is to expand on your understanding of the Swing API, as well as to continue to improve your skills working with Java objects.

Here's a small screenshot of what your new program might look like:

Here is what you must provide:

  1. A 10 x 10 grid of buttons that initalize in state "A". You may indicate state "A" by a text label (I used "wow"), but I recommend using a small, colorful image, such as a red ball or a green square. (Don't use "A" for the label - that's just boring!)

  2. Any button in the above grid, when clicked, should respond by flipping from its current state to the "other" state, "B". Likewise, please indicate state "B" via a different image or label. (Not "B", please!)

  3. At the bottom or side of your window, provide a special button called "step" that, when clicked, inverts the state of all 100 buttons.

  4. Your application should perform these update operations only when buttons are actually pressed. This means that it should be event-driven, and not have a loop that constantly polls for user interactions. An event-driven approach will make your program much more efficient as far as CPU usage is concerned.

  5. Finally, make sure to configure your program so that it will shut down the Java VM when the user clicks on the close-window button.

Sounds easy enough, right?

Here are some other tips:

Extra Credit:


Updated February 6, 2008. Copyright (C) 2003-2008, California Institute of Technology.