Perhaps a picture is needed. Clouds represent class definitions, solid rectangles represent objects, and dotted rectangles represent the static part of a class.
Look back at the example program as you study the diagram.
ButtonDemo2extends the class
main()method is static, so is not part of any object. It contains two reference variables:
ButtonDemo2frame and its button are displayed on the screen.
ButtonDemo2frame is registered as a listener for Action Events.
WindowQuitterobject was registered as a listener for window events.
Don't be discouraged if this is less than perfectly clear! It usually takes some time to get all of these relationships straight. A bit more practice would not hurt, either.
(Thought question: ) Must you use the "close button" of a frame
to quit the program? Could a
JButton be used?