Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

Notice that in this little program I did something kind of cool: I made the CBn class a button that is its own action listener. Nice, right? So the line

is basically saying "I am my own ActionListener".

  1. [15pts] Instead of writing HW1Frame F = new HW1Frame(); for the first line of main, suppose I had written:
    JFrame F = new HW1Frame();
    Would the result be: compile-time error, run-time error, or OK? Explain your answer thoroughly?
  2. [15pts] Compile and run the above program. You'll notice that clicking the x at the top of the window does not exit the program. I'd like to change things so that clicking on the x closes the program, but before doing so prints the number of button clicks on the screen, like this:
    Button clicked 3 times.
    The nicest way to do this is to make the CBn class listen not only for button clicks, but also for window closing events!

    When we define a class that listens for window events, we must either implement the WindowListener interface or extend the WindowAdapter class. (see the previous lesson's notes) Extending the class is certainly easier. Explain why, however, if we want to modify our CBn class so that it not only serves as a button and listens for button clicks, but also listens for window events, we cannot extend WindowAdapter. Instead, wee must implement WindowListener.

  3. [70pts] Actually modify the Ex1 program as described in the previous problem: i.e. when the user clicks on the x in the window, the program exits, but before exiting it prints the number of times the button has been clicked out on the screen.
Turn In A printout of your source code. You must honestly check one of the following:
      ____ My program works completely and correctly

      ____ My program does not work completely and correctly