CSSE 220 – Object-Oriented Software Development

Homework 19

Objectives

More practice with event-based programming in Swing.

Tasks

  1. Complete the assigned reading for the next session, according to the course schedule.

  2. Complete the assessment exercise over this reading on ANGEL (under Lessons → Assignments).
  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. You should have completed the CheckingAccount exercise that you started in class today. If not, complete it as follows:
        • In Eclipse, checkout the Inheritance project from your individual repository.
        • Per the UML for the Banking example, implement a CheckingAccount class that extends BankAccount.
        • You should complete this in the banking package.
    3. Linear Lights Out: Implement the game Linear Lights Out in the linearLightsOut package. 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 homework or examples, or is in the Java API documentation for JButton. Remember to ask for help if you get stuck.

      Here are the various stages you should complete:

      • Stage 0: Examine the main method in the LinearMain class in the linearLightsOut package in the Inheritance project that you checked out in class. This is all the code that we supply for the project — the rest is your responsibility.
      • Stage 1: Display a frame with the right title.
      • Stage 2: Display the right number of buttons in the frame (see the nButtons variable in LinearMain.main) without worrying about event handling or the symbols on the buttons. For full credit, your final solution must work with any nButtons greater than 2.
      • Stage 3: Make sure the buttons are initialized to random symbols (Xs and Os, 50% probability each).
      • Stage 4: Implement a working Quit button (This involves implementing an event handler for the Quit button).
      • Stage 5: Implement a working New Game button. When the button it pressed, the game should reset the symbol buttons to a new set of random symbols.
      • Stage 6: Set up event handlers for the symbol buttons that correctly toggle the symbols as described above.
      • Stage 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:

      1. The setText() and getText() methods of JButton are your friends.
      2. You do not need to use inheritance to solve this problem; your BallWorlds project will give you practice with that.
        • You may, however, use inheritance in this project if you wish: extending JFrame, JButton, and/or JPanel, for example.
        • Here's a sample UML diagram that you may find helpful

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

Remember, in all your code:

Here is the grading rubric for this assignment.

Turn-in Instructions

Turn in your programming work by committing it to your SVN repository.