I wrote my own customerized dialog--subclassed JDialog. When the user push the OK button of the dialog, it should close the dialog and transfer the input data to the parent frame and fire some event of the parent frame. But I don't know how can I fire the parent frame's event in the action listener of the dialog's OK button. Can you help me with this? Please show some sample codes. Thanks a lot.
Does the event that gets fired change depending on the data returned from the dialog box, or is it always the same event?
Joined: Mar 20, 2001
It is the same event, but it needs to process the data which user input in the dialog. I tried: dialog.setVisible(true); //get data from dialog then go on. So I suppose that the dialog is modal, and after setVisible(true), other commands can go on only after user closes the dialog. And it works well. But I am afraid that such a solution is not "pretty". I wanted to get such an interface like JOptionPane.showDialog......
It is not modal unless you say it is (at least for Dialogs).. but here is code that I made a few months back. Originally I had it extending Dialog, but with a few modifications it now extends JDialog.And here is the actual mcDialog class that extends JDialog Hope that helps.
Joined: Mar 20, 2001
Thank you very much. I think your solution is the same as mine. You see: after setVisible(true); then you called getText3(). So the getText3 is not triggered by pushing the OK button. The OK button only fires the dispose event. BTW: instead of dispose(), I used only setVisible(false). Which differences are there? The dialog I need to show for many times, so I don't need to destroy it.
I forgot to mention... a point I wanted to make was about the dispose.
If you know VB at all, you'll understand the // comment I made in the code, but for those who don't
dispose() simply tells the JVM that it can reclaim all the resources that were used to create the JDialog (graphical stuff), but as near as I can determine.. it does not actually blow away the dialog box (and because the dialog object contains the values, they aren't lost either). You would only accomplish this by setting the reference to null (dg = null ;) Which you MAY need to do, if you want the dialog to come up 'fresh' each time.
See what I mean by doing this:The second showing of the dialog box, retains the value you put in there before. If you wanted a clean dialog, you'd have to set dg=null, and make a new one. (or otherwise override the setVisible method to reset things back to default)
[This message has been edited by Mike Curwen (edited June 04, 2001).]