Return result from JOptionPane to JFrame
Hi.
I have Frame and button in that Frame. When I click on the button it opens
Dialog. In that Dialog is button. When I click on that button it returns something to the frame (for example draw Rectangle or Oval).
I have tried few times, but it wasn't good :-(
My thinking:
class NewFrame extends JFrame
class NewPanel extends JPanel
in NewPanel I have button.add(ActionListener)
NewDialog extends JDialog
DialogPanel extends JPanel
in DialogPanel there is dialogButton.add(ActionListener)
Problem is how with using mouse clicks on dialogButton to affect the change of NewFrame (for example draw Rectangle in that NewFrame).
Please give me advice.
Re: Return result from JOptionPane to JFrame
See How to Make Dialogs (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components). Most notably you could use a JOptionPane showOptionDialog(...) to accomplish this (the selection is returned) as demonstrated in the tutorial.
Re: Return result from JOptionPane to JFrame
That's useful, but what if I want to have three JTextField components in Dialog. o:-)
Re: Return result from JOptionPane to JFrame
Re: Return result from JOptionPane to JFrame
The informer is here x-(
Another harmless defamation. Nevermind.:-j
Best regards.
Re: Return result from JOptionPane to JFrame
It's only a defamation if you consider it a defamation. But if you consider cross posting wrong, then why did you do it in the first place?
db
Re: Return result from JOptionPane to JFrame
Cross posting is not against the rules here, however it would be nice if you posted links to the other places you have asked your question so we can try to keep the conversation as un-fragmented as possible. (of course, please do follow the rules of any other forums you may be posting on, as some do disallow cross-posting, or frown upon it)
If you have three values you want to return, there are two main ways to do this:
1. Have your dialog return a "wrapped object" which contains the three strings you want.
2. Have your main application be added to some sort of a listener (probably an ActionListener for the "ok" button on the dialog), and then when that action is triggered, simply extract the information you want directly from the textfields of the dialog.
Re: Return result from JOptionPane to JFrame
I don't say cross posting is against the rules. I pointed out a cross post without further remark or comment. However, the cross poster's reaction in this thread shows that they were unsettled by the disclosure.
"cselic" has also sent me a vitriolic PM on the other forum, which i have quoted in the thread after reporting the violation of the site's terms of use.
Incidentally, an earlier topic by the same poster "Sort in Cyrillic order" was also cross posted, and at no point did the poster inform either forum of the discussions on the other one.
db