Click to See Complete Forum and Search --> : Subform Returns A Value
MethadoneBoy
Apr 18th, 2007, 04:45 AM
Hi guys,
Very noob-ish question here. How is it possible to programme a pop-up GUI (launched by clicking a button on a main GUI) to return a value? For instance, say you open this subform and it contains a TextField. You want whatever the user enters in the field to be visible to the main form once the subform has closed. Can this be done?
Thanks.
CornedBee
Apr 18th, 2007, 03:30 PM
Of course it can be done.
The simplest way is by using the static methods of JOptionPane. They provide various standard dialog boxes.
Failing that, there are various methods.
1) The form opener could provide a place to store the value.
2) The form opener could register a form listener on the form to detect it closing, then simply read out the relevant values. This is probably the best way as it is not too hard to implement, solves the issue of how to know when to fill in the data, and introduces no coupling from the child to the parent.
3) The form could be passed a reference to the opener and set the values on closing directly. This is the worst option because it introduces child->parent coupling. To slightly alleviate this, you could just pass a specific interface that the parent implements for this purpose.
JOptionPane is pretty flexible, though, and in general the preferred way of doing such things.
MethadoneBoy
Apr 19th, 2007, 05:46 AM
Of course it can be done.
The simplest way is by using the static methods of JOptionPane. They provide various standard dialog boxes.
Failing that, there are various methods.
1) The form opener could provide a place to store the value.
2) The form opener could register a form listener on the form to detect it closing, then simply read out the relevant values. This is probably the best way as it is not too hard to implement, solves the issue of how to know when to fill in the data, and introduces no coupling from the child to the parent.
3) The form could be passed a reference to the opener and set the values on closing directly. This is the worst option because it introduces child->parent coupling. To slightly alleviate this, you could just pass a specific interface that the parent implements for this purpose.
JOptionPane is pretty flexible, though, and in general the preferred way of doing such things.
Thanks for the response. I have actually used JOptionPanes a couple of times in my app but for one particular data-entry component, I'm sticking with using a subform for the time being due to the volume of data that this subform is designed to record.
Also, one aspect of my app invloves using a FileChooser object to browse to the location of an XML file and reading in valued contained within. I'd like to implement this function on another subform and I'm not sure how a FileChooser object can be placed on a JOptionPane (can it?).
The second option you mentioned sounds interesting. Are there any tips/tutorials you can point me to that would show me how to implement it?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.