I have a JFrame, and when a button is clicked, it needs to pop up a custom JDialog. In this JDialog, a user inputs data and clicks ok to pass the data back to the JFrame, so it can be saved off. I can do this using Flex/Actionscript 3.0, but can't figure out how to get it working in Java. Below are code fragments from AS3.0.
perhaps the simplest way is to set the dialog's modality to true, then when you create the dialog you also call the method that will return the data. the data will not be returned until the dialog disposes (or visible false).
simple demo (click 'get name', enter something into the textfield, click 'ok'
Thank you, but I don't believe this will work (because there will be a cancel button that calls dispose(); ). Is there any good way to do this using events and listeners?
Hmm, I think this would work, but I would like to have the dialog window not care what called it. I've been looking into using addActionListener() and dispatchEvent() and have tried created my own custom event/listener but can't seem to figure out exactly what to do. Any suggestions?
The text would be set to the value of the input every time, and I need it to be able to not do anything if the user clicks a 'Cancel' button. I would also prefer this to be done using listeners, as I need it as reusable as possible.