Results 1 to 14 of 14
  1. #1
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Help with JOptionPane.showInputDialog

    How do you use JOptionPane.showInputDialog to display a text box for user input?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Help with JOptionPane.showInputDialog

    What's a text box?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Help with JOptionPane.showInputDialog

    From the google search "showInputDialog tutorial":
    JOptionPane showInputDialog examples | JOptionPane show input | devdaily.com
    I like likes!

  4. #4
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: Help with JOptionPane.showInputDialog

    Quote Originally Posted by Sierra View Post
    From the google search "showInputDialog tutorial":
    JOptionPane showInputDialog examples | JOptionPane show input | devdaily.com
    I have used that exact coding and I get numerous errors when I try to run javac to create my class file.
    The 1st one is error: class, interface or enum expected


    EDIT +++
    I am using Notepad++ when trying this coding as well, does that have an affect on why I am getting that error?
    Last edited by Rahim2312; 04-30-2012 at 09:47 PM.

  5. #5
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: Help with JOptionPane.showInputDialog

    Quote Originally Posted by Rahim2312 View Post
    I have used that exact coding and I get numerous errors when I try to run javac to create my class file.
    The 1st one is error: class, interface or enum expected


    EDIT +++
    I am using Notepad++ when trying this coding as well, does that have an affect on why I am getting that error?
    I hope you don't expect us to guess, because that is often counter-productive. Providing code as an SSCCE and giving all errors you receive does wonders in helping you get help

  6. #6
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: Help with JOptionPane.showInputDialog

    Maybe I am just impatient but when I try to upload a screenshot, my screen just shows a gray textbox it never opens up to show what to attach....Let's start with what has been proven to work, not my very newbie code I am trying.

    Trying to run the code from the website you provided, I am only getting one error and that is:

    class JOptionPaneShowInputDialogExample1 is public, should be declared in a file named JOptionPaneShowInputDialogExample1.java
    public class JOptionPaneShowInputDialogExample1

  7. #7
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: Help with JOptionPane.showInputDialog

    What you posted (or what you were hoping to post - a screenshot) gets no closer to helping us understand what/where the problem is. Please read post 5

  8. #8
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: Help with JOptionPane.showInputDialog

    I thought post 5 was saying to provide code, and provide the error?

    I was running this code from post # 3

    JOptionPane showInputDialog examples | JOptionPane show input | devdaily.com

    and I posted the error received. Am I not understanding the post?

  9. #9
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: Help with JOptionPane.showInputDialog

    Quote Originally Posted by Rahim2312 View Post
    I thought post 5 was saying to provide code, and provide the error?
    Yes, and you provided no code. The link contains several pieces of code...but I guess you just want a guess, so here's mine: class files must be named the same as the containing public class within.

  10. #10
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: Help with JOptionPane.showInputDialog

    Quote Originally Posted by doWhile View Post
    Yes, and you provided no code. The link contains several pieces of code...but I guess you just want a guess, so here's mine: class files must be named the same as the containing public class within.
    Apalogies...

    Java Code:
    import javax.swing.*;
    
    /**
     * JOptionPane showInputDialog example #1.
     * A simple showInputDialog example.
     * @author alvin alexander, devdaily.com.
     */
    public class JOptionPaneShowInputDialogExample1
    {
      public static void main(String[] args)
      {
        // a jframe here isn't strictly necessary, but it makes the example a little more real
        JFrame frame = new JFrame("InputDialog Example #1");
    
        // prompt the user to enter their name
        String name = JOptionPane.showInputDialog(frame, "What's your name?");
    
        // get the user's input. note that if they press Cancel, 'name' will be null
        System.out.printf("The user's name is '%s'.\n", name);
        System.exit(0);
      }
    }

  11. #11
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: Help with JOptionPane.showInputDialog

    Is the code contained within a file named JOptionPaneShowInputDialogExample1.java, as the error code states?

  12. #12
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: Help with JOptionPane.showInputDialog

    It is contained within a file titled Test1.java

  13. #13
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Help with JOptionPane.showInputDialog

    As doWhile said:
    One way: Rename the file to JOptionPaneShowInputDialogExample1.java
    Other way: Rename the class and its references to Test1 and you may have no error anymore
    I like likes!

  14. #14
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: Help with JOptionPane.showInputDialog

    Quote Originally Posted by Sierra View Post
    As doWhile said:
    One way: Rename the file to JOptionPaneShowInputDialogExample1.java
    Other way: Rename the class and its references to Test1 and you may have no error anymore
    I must have missed doWhile's post....renaming the class to the filename allowed it to run properly. Thank you all

Similar Threads

  1. JOptionPane.showInputDialog with only 1 correct answer
    By Gladiat0r in forum New To Java
    Replies: 1
    Last Post: 03-18-2012, 09:42 PM
  2. string prompt doesn't appear in showInputDialog
    By saxophone in forum New To Java
    Replies: 4
    Last Post: 04-01-2010, 10:05 PM
  3. Problem in showInputDialog
    By mghaheri in forum New To Java
    Replies: 1
    Last Post: 03-05-2009, 11:29 PM
  4. JOptionPane.showInputDialog
    By mayhewj7 in forum New To Java
    Replies: 5
    Last Post: 02-25-2009, 06:04 AM
  5. Problem with JOptionPane.showInputDialog()
    By romina in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 05:33 AM

Posting Permissions

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