JFrame addWindowListener doesn't work -- alternative close button action

Hello,

I am trying to get a program to save some data to a DB before exiting; So I need to assign a customer listener for the close button of the program.

This is that what I have tried so far:

privatevoid initComponents(){

this.addWindowListener(new WindowAdapter(){

publicvoid WindowClosing(WindowEvent e){

JOptionPane.showMessageDialog(thisInstance,"Window Event Handled Properly");

}

});

This Dialog never gets displayed when attempting to close the parent JFrame ("this"); which means the WindowListener isn't working. What's wrong?

Thanks

[936 byte] By [frost986a] at [2007-11-27 11:56:27]
# 1

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6260648

srinivassa at 2007-7-29 19:07:40 > top of Java-index,Desktop,Core GUI APIs...
# 2

try using windowListener than windowAdapter

public aFrame extends JFrame implements WindowListener {

public aFrame(){

addWindowListener( this );

}

public void windowActivated(WindowEvent e){}

public void windowDeactivated(WindowEvent e){}

public void windowOpened(WindowEvent e){}

public void windowClosing(WindowEvent e){

// your code

}

public void windowClosed(WindowEvent e){}

public void windowIconified(WindowEvent e) {}

public void windowDeiconified(WindowEvent e) {}

}

Yannixa at 2007-7-29 19:07:40 > top of Java-index,Desktop,Core GUI APIs...
# 3

First, it's "public void windowClosing(...)", not "WindowClosing". Java is case sensitive, and using WindowAdapter certainly masks this problem.

Also, you maybe want to be calling

frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

and having your window listener close/dispose the frame based on some condition (dialog response, DB saving completion, etc.)

bsampieria at 2007-7-29 19:07:40 > top of Java-index,Desktop,Core GUI APIs...
# 4

Thank You,

The problem was the case of "w" in windowClosing(...)

It was also helpful to know that this.handleEvent(Event e) has been deprecated.

Much Appreciated

frost986a at 2007-7-29 19:07:40 > top of Java-index,Desktop,Core GUI APIs...