Lab 4: Interfaces and Swing


Your goal this week is to expand on your understanding of the Swing API as well as to hammer home the fundamental tools for working with Java objects.

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

More explicitly, you must provide:

  1. A 10 x 10 grid of buttons that are initialized in state "A". You may indicate state "A" by a text label (e.g. "wow" in the picture) but we recommend using a small, colorful image, such as a red ball or a green square.
  2. Any button in the above grid, when clicked, should respond by flipping from its current state to the "other" state, state "B". Likewise, please indicate state B via a different image or label.
  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. Add a listener such that when the user clicks on the close window button, the window closes and the Java VM exits back to the shell.

Sounds easy enough, right?


Java language issues


Design advice

Object-oriented languages provide many ways to design programs that achieve the same goals. Some of these designs are good and some aren't. In this and future labs we'll be supplying some advice on design. These are not hard-and-fast rules, just suggestions, but if followed you will have an easier time with the assignments (and hopefully start to develop your design sense as well).


Extra credit: