Java Programming - Event Fire When User Presses The "X" On JFrame?

i was wondering what event is fired when you press the "X", in the top right hand corner, of a JFrame? i need to know it for data saving reasons
[151 byte] By [Alex1989a] at [2007-11-26 23:04:58]
# 1
no need to capture an event. just stick a WindowListener on the JFrame. when it's closing, the windowClosing method will be called. put a call to your cleanup code in that
georgemca at 2007-7-10 13:57:45 > top of Java-index,Java Essentials,Java Programming...
# 2

k thnx. i tried this:

private class Listener extends MouseAdapter, WindowAdapter implements ActionListener{

//CODE HERE

}

but it give me an error. as u can see im already using a MouseAdapter and an ActionListener so how would i fit a WindowAdapter into the picture?

Alex1989a at 2007-7-10 13:57:45 > top of Java-index,Java Essentials,Java Programming...
# 3

A class can not extend more than one base class.

You can either implement WindowListener (no limit on number of interfaces implemented),

or write a new class that extends WindowAdapter.

I would go for the second, because I think you are listening to the window

and to the mouse for different reasons, so why stick unrelated code

together in one class? That's a bad design, like combining fields of

information about a Person (name, age, phone number) and fields

of information about a Dog (breed, weight) into a single DogOwner class.

DrLaszloJamfa at 2007-7-10 13:57:45 > top of Java-index,Java Essentials,Java Programming...
# 4

ok ... you get an error because you cannot extend multiple classes. you can impliment multiple interfaces, and extend multiple interfaces with an interface, but you can not extend multiple classes (can you be both whale and human? no, but you could be both male, african american, & human ...)

a better way to go about this (if you are trying to have one listener type class, as in the traditional MVC approach), is to have one class implementing both MouseListener & WindowListener.

(ex class MegaListener implements MouseLIstener, WindowListener )

there are some j-rigged approaches to not having to define all the methods in the WindowListener & MouseListener interfaces, but i encourage you to spend the extra 10 minutes doing it the foolproof way.

good luck!

systemNinea at 2007-7-10 13:57:45 > top of Java-index,Java Essentials,Java Programming...
# 5
i was thinking of making a sub class for each of my different listeners (action, mouse and window listeners). do u think that this would be a good idea or is it also bad programming practice?
Alex1989a at 2007-7-10 13:57:45 > top of Java-index,Java Essentials,Java Programming...
# 6
Good programming practice is for a class to have high cohesion: http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29
DrLaszloJamfa at 2007-7-10 13:57:45 > top of Java-index,Java Essentials,Java Programming...