/** * If you register an object of this class as a listener to any * object of the class JFrame, then if the user clicks the * close-window button of the JFrame, the object of this class * will end the program and close the JFrame. */

Let's discuss this sample here. Please post questions/remarks as reply to this post.

Gillius:
If I am being too pedantic, let me know...

Calling a class Dialog when it is a type of a frame is awkward when dialogs and frames are very different in Swing and there is actually a class java.awt.Dialog.

Instead of the WindowDestroyer class, there exists the method JFrame.setDefaultOperationOnClose( JFrame.EXIT_ON_CLOSE ); that does the same thing. You can also choose dispose, hide, or no action.

Having a defined WIDTH and HEIGHT is probably not preferrable in a Java environment that is supposed to be DPI-independent. Maybe a better option is to pack() the frame first? Perhaps packing doesn't work well for this example -- I didn't run this code :(.

Also as a random tip, Java version 1.4 has setLocationRelativeTo( null ); which places the window in the center of the screen instead of at the upper-left corner. Java version 1.5 also adds the ability to call setLocationByPlatform( true ); which lets the operating system decide where to put the window, which is likely the best option since the operating system knows about things like multi-monitor displays and such.

BTW: if this is distracting to the real lesson here, I apologize, as what I was discussing is probably not beginner's topics except for the pack and setDefaultCloseOperation.

louiecerv:
While it may intimidate the timid and the weak of heart, your remarks are actually very much welcome!

For the absolute beginners, which is majority in this class, some of the details can be a bit too much at this stage. Still, it is helpful to everyone because it reveals how much more there is to be learned.

Inputs from someone with broad industry experience are always valuable. The class should strive for better quality of output and avoid the pitfalls you pointed out.