• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help! Question about JDialog...

 
Jamy Wang
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to show a JDialog and input some information. But I don't know how to get the value inputed.
For example, I want to input name, age, address in the dialog. And get the value when click OK on the dialog. What should I do? I found JOptionPane.showinputdialog can not do it. Because it can not return an array of value.
Thank you for your help in advance.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,
You have (at least) a couple of ways of doing this. You could make your fields in your class that extends JDialog public - that way you can just access them after the user has completed input.
Or you could add a method to your class that extends JDialog which does the work of displaying the dialog, then getting the user's input and passing it back to the calling class as an array - similar to how JOptionPane works.
While on that second option - have you tried looking at the source code for JOptionPane to see how they return values?
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic