Closing a Dialog Box correctly

Every time I try and close a dialog box I get runtime errors within my code. What I do is click a button which is suppose to close the dialog box. Can someone tell me the correct way to close a dialog box?
[219 byte] By [garbersb] at [2007-9-26 2:49:37]
# 1
dispose() should do it, i.e. myDialog.dispose();
isjm at 2007-6-29 10:35:42 > top of Java-index,Desktop,Core GUI APIs...
# 2

When I just call a dispose(); I still am getting run time errors. Here is the code I have in my actionEvent when the button is pushed.

public void actionPerformed(ActionEvent evt) {

try {

Object source = evt.getSource();

if (source == _dialogButton) {

System.out.println("Dialog Button was pressed");

//_dialogWindow.hide();

//this.hide();

_dialogWindow.dispose();

//this.dispose();

}

}

I eventually get the following runtime error.

Exception occurred during event dispatching:

java.lang.IllegalArgumentException: adding a window to a container

at java.awt.Container.addImpl(Container.java:339)

at java.awt.Container.add(Container.java:231)

at frameApplet.buildGui(frameApplet.java:40)

at frameApplet.<init>(frameApplet.java:17)

at buttonApplet.actionPerformed(buttonApplet.java:23)

at java.awt.Button.processActionEvent(Button.java:329)

at java.awt.Button.processEvent(Button.java:302)

at java.awt.Component.dispatchEventImpl(Component.java:2595)

at java.awt.Component.dispatchEvent(Component.java:2499)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:336)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh

read.java:134)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

ad.java:101)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:96)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:88)

I don't quite understand why I am getting this runtime error. Any help would be appreciated.

garbersb at 2007-6-29 10:35:42 > top of Java-index,Desktop,Core GUI APIs...
# 3

I got rid of the run time problem. Instead of using dispose() I ended up using show() and hide(). When the initial GUI came up I had the hide() method called and when the button was pushed to bring up the dialog box show() was called. I then called hide() again when the ok button was pushed. This called no run -time error.

garbersb at 2007-6-29 10:35:42 > top of Java-index,Desktop,Core GUI APIs...