Results 1 to 2 of 2
  1. #1
    Joshuak is offline Member
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Question Keeping a JOptionPane window open after selection.

    Hello,

    First off let me just say that I am a complete beginner with Java; so if my question seems stupid it's probably because I don't know enough to ask the right question. I'll start by explaining what I'm trying to do and then ask my question.

    Goal:
    Create a small program that tells the user the birthday of the name typed in. I would like to be able to type a name get their birthday and then be taken back to the "name prompt" again.

    Problem:
    After I type my first name into the dialog box the program tells me the birthday and then automatically shuts down.

    Question:
    How can I get it to go back to the start after it displays the birthday instead of shutting down?

    Current Code:

    import javax.swing.JOptionPane;
    public class birthday {

    public static void main(String[] args) {
    String response;
    response=JOptionPane.showInputDialog("Who's Birthday would you like to know?");
    if (response.equals("Jessica"))
    JOptionPane.showMessageDialog(null, "December 17, 1985");
    else
    if (response.equals("Jessica Hildebrandt"))
    JOptionPane.showMessageDialog(null, "December 17, 1985");
    else
    if (response.equals("Nate"))
    JOptionPane.showMessageDialog(null, "December 13, 1980");
    else
    if (response.equals("Nathan"))
    JOptionPane.showMessageDialog(null, "December 13, 1985");
    else
    if (response.equals("Nathan Hildebrandt"))
    JOptionPane.showMessageDialog(null, "December 13, 1985");
    else
    if (response.equals("Nate the great"))
    JOptionPane.showMessageDialog(null, "December 13, 1985");
    else
    if (response.equals("Kaylee"))
    JOptionPane.showMessageDialog(null, "July 28, 2006");
    else
    if (response.equals("Kaylee Hildebrandt"))
    JOptionPane.showMessageDialog(null, "July 28, 2006");
    else
    if (response.equals("Stugry"))
    JOptionPane.showMessageDialog(null, "July 28, 2006");
    else
    if (response.equals("Bethany"))
    JOptionPane.showMessageDialog(null, "April 18, 1985");
    else
    if (response.equals("Bethany Hildebrandt"))
    JOptionPane.showMessageDialog(null, "April 18, 1985");
    else
    if (response.equals("Beth"))
    JOptionPane.showMessageDialog(null, "April 18, 1985");
    else
    if (response.equals("Mom"))
    JOptionPane.showMessageDialog(null, "April 14, ????");
    else
    if (response.equals("Shirley Hildebrandt"))
    JOptionPane.showMessageDialog(null, "April 14, ????");
    else
    if (response.equals("Shirley"))
    JOptionPane.showMessageDialog(null, "April 14, ????");
    else
    if (response.equals("Dad"))
    JOptionPane.showMessageDialog(null, "October 4, ?????");
    else
    if (response.equals("Grant Hildebrandt"))
    JOptionPane.showMessageDialog(null, "October 4, ????");
    else
    if (response.equals("Grant"))
    JOptionPane.showMessageDialog(null, "October 4, ????");

    }

    }
    Last edited by Joshuak; 12-10-2011 at 07:21 AM.

  2. #2
    jiffi is offline Member
    Join Date
    Oct 2011
    Posts
    79
    Rep Power
    0

    Default Re: Keeping a JOptionPane window open after selection.

    use a loop to go back to the beginning of the program. Don't forget to give an option to exit the program, or the loop will go on forever.

    Also use code /code tags, to make your code easier to read

Similar Threads

  1. Replies: 2
    Last Post: 10-20-2011, 03:43 PM
  2. Replies: 1
    Last Post: 07-25-2011, 11:24 AM
  3. Replies: 4
    Last Post: 02-07-2011, 09:43 AM
  4. Keeping one window above another
    By porchrat in forum AWT / Swing
    Replies: 3
    Last Post: 01-27-2011, 09:11 AM
  5. How do i show all the values in one window(JOptionPane)??
    By Antonioj1015 in forum Advanced Java
    Replies: 1
    Last Post: 11-25-2009, 05:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •