• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with passing events between components.

 
Ranch Hand
Posts: 36
Mac Eclipse IDE Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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'

 
Chris Waguespack
Ranch Hand
Posts: 36
Mac Eclipse IDE Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thank you,
Chris
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
another way

 
Chris Waguespack
Ranch Hand
Posts: 36
Mac Eclipse IDE Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thank you,
Chris
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> but I would like to have the dialog window not care what called it.

that's the first example I posted
 
Chris Waguespack
Ranch Hand
Posts: 36
Mac Eclipse IDE Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> that's the first example I posted

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.

Thank you,
Chris

P.S. Thanks for the help so far.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here's the first example modified for cancel/ok (with empty textfield)/ok



I don't fully understand the requirements - perhaps all you need is a
JOptionPane.showInputDialog(...)
 
Chris Waguespack
Ranch Hand
Posts: 36
Mac Eclipse IDE Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help. I finally decided to go with an MVC approach and that seems to be working like I need it to.
 
reply
    Bookmark Topic Watch Topic
  • New Topic