Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Return result from JOptionPane to JFrame

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    10
    My Mood
    Nerdy
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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.

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    10
    My Mood
    Nerdy
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Return result from JOptionPane to JFrame

    That's useful, but what if I want to have three JTextField components in Dialog.

  4. #4
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Return result from JOptionPane to JFrame


  5. #5
    Junior Member
    Join Date
    Apr 2010
    Posts
    10
    My Mood
    Nerdy
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Return result from JOptionPane to JFrame

    The informer is here
    Another harmless defamation. Nevermind.

    Best regards.
    Last edited by cselic; May 8th, 2010 at 06:41 PM.

  6. #6
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default 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

  7. #7
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.
    Last edited by helloworld922; May 10th, 2010 at 12:19 AM.

  8. #8
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default 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

Similar Threads

  1. Using Icons in JOptionPane
    By Jchang504 in forum AWT / Java Swing
    Replies: 3
    Last Post: September 19th, 2014, 02:28 PM
  2. How do i show all the values in one window(JOptionPane)??
    By Antonioj1015 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 25th, 2009, 09:24 PM
  3. Average program with array and loop and JOptionPane.
    By jeremykatz in forum AWT / Java Swing
    Replies: 6
    Last Post: October 25th, 2009, 02:33 PM
  4. JOptionPane Question/ Printing
    By 03EVOAWD in forum AWT / Java Swing
    Replies: 2
    Last Post: August 31st, 2009, 09:17 AM
  5. Problem of getting result than SQL to JTable
    By MS_Dark in forum Exceptions
    Replies: 1
    Last Post: March 10th, 2009, 06:26 AM