Click to See Complete Forum and Search --> : Triggering an event when JDialog closes


MarkLeong
08-11-2003, 08:29 PM
I need to open a connection to a database when JDialog opens. I put the code in the constructor.

I want to close the connection when JDialog closes (using setVisible(false)). Where should I put the code?

dimitrylevin
08-11-2003, 08:55 PM
I dont know if this would work but you could try overriding the setVisible() method.

public class MyDialog extends JDialog {

public void setVisible(boolean b) {
super.setVisible(b);
if(b == true) {
//open connection
}
else {
//close connection
}
}

}

MarkLeong
08-11-2003, 09:36 PM
Thanks. Will give it a go.

dimitrylevin
08-11-2003, 10:49 PM
ok.

Stuka
08-12-2003, 09:07 AM
Another possibility is to use the WindowListener interface (or the WindowAdapter class that implements it). These classes respond to events such as window openings, closings, gain/loss of focus, etc.