IC211 Spring AY 2020
Name (Last, First): ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
Ex20.java | CBn.java |
|
|
HW20Frame.java | |
|
Notice that in this little program there is something kind of cool: the CBn class is a button that is its own action listener. Nice, right? So the line
this.addActionListener(this);
is basically saying "I am my own ActionListener".
HW20Frame F = new HW20Frame();
for the first line of main, suppose I had written:
JFrame F = new HW20Frame();Would the result be: compile-time error, run-time error, or OK? Why? Explain your answer thoroughly!
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, we must implement WindowListener.
Turn in: this sheet, the codeprint of your source code, and screen captures of both your GUI and the terminal window showing the output when your GUI window is closed.
Don't forget to add proper Javadoc formatted comments in the source code! Note: You do NOT have to write Javadoc comments for empty block methods that exist only to satisfy implementation requirements for interfaces.