CSSE 220 – Object-Oriented Software Development

Homework 15

Objectives

More practice with event-based programming in Swing.

Tasks

  1. Complete the assigned reading for the next session: §10.8–10.11. (See schedule for topics to focus on.) As you read, see if you can answer the self-check questions. If there is something you do not understand, make note of it so you can ask about it.
  2. Edit the Big Java Review Wiki on ANGEL, adding answers to two of the review exercises from chapter 10. Be sure to carefully follow the instructions for doing this that are posted on the Wiki.
  3. Programming:
    1. Your programming work for this part must be done in the Inheritance project inside Eclipse. Use the SVN Repository Exploring perspective to check out this project, then switch back to the Java perspective.
    2. In-class exercises:
      1. Implement CheckingAccount
    3. Linear Lights Out: Implement the game Linear Lights Out. In Linear Lights Out, the user is presented with an array of buttons that are randomly initialized to either Xs or Os, 50% probability each. Clicking on a button changes the symbol of the button and both its left and right neighbors. Buttons on the end just change their own symbol and their one neighbor’s symbol; the buttons don’t “wrap around”. The object of the game is to reach a state where the buttons all show the same symbol, whether Xs or Os doesn’t matter.

      We’re providing a lot less “scaffolding” for this problem than most of the previous ones. Everything you need to solve the problem has either appeared in previous homeworks or examples, or is in the Java API documentation for JButton. Remember to ask for help if you get stuck. Here’s a suggested plan of attack:

      1. Display a frame with the right title.
      2. Display the right number of buttons in the frame (see LinearMain.BUTTON_COUNT) without worrying about event handling or the symbols on the buttons. For full credit, you final solution must work with any BUTTON_COUNT greater than 2.
      3. Make sure the buttons are initialized to random symbols.
      4. Implement an event handler for the Quit button.
      5. Implement an event handler for the New Game button. This should reset the symbol buttons to a new set of random symbols.
      6. Set up event handlers for the symbol buttons that correctly toggle the symbols as described above.
      7. Check for a win and notify the player in some way. Changing the window title would suffice. (If you do that, be sure to change it back when the player clicks New Game.)

      Hints:

      • The setText() and getText() methods of JButton are your friends.
      • You do not need to use inheritance to solve this problem. We’ll start working with that on Monday.

      Here’s a screen shot of the game in progress:

Turn-in Instructions

We will grade your Wiki contributions using ANGEL. Turn-in your programming work by committing it to your SVN repository.