• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Returning a value from a modal dialog?

 
Bartender
Posts: 1757
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When my JFrame calls a modal dialog for the user to enter a date, I want to return that date to my calling JFrame and set a date field (JTextField) when the dialog exits.
How do you do this?
Thanks in advance for any ideas.
Mike.
 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,
Here's what you need to do. Extend the JDialog class. You should have a private field called myDate, or whatever. Then you should have a set and get method for this field. The set method should be private, since I'm assuming that you would not want to make it possible for an outside class to modify this field. And the get method should be either protected or public, depending on which packages you want to have access to this dialog. When the dialog closes, you call the set method and set the date field internally, before calling dispose(). Since the dialog is modal, your calling class execution will stop and will wait on the JDialog to close. After the statement that calls the JDialog in your calling class, you call the get method from the JDialog and set your text field on the JFrame. Hope this helps!

Barry
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic