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 7 of 7

Thread: Need help with user input/output for GUI.

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need help with user input/output for GUI.

    //This is my code so far. I'm suppose to have the user enter this:

    user enters a int between <= 12 then would display this message Howdy youngster

    user enters a int between >12 and <20 then would display another message displays You're getting old. etc..





    I dont know how to set it up so the number i enter coordinates with the right message.





    public class L4_SimpleCalc
    {
    public static void main (String arg[] )
    {
    JOptionPane.showMessageDialog(null, "The Old Man says:");

    //Read in a value
    String enterNum = JOptionPane.showInputDialog(null, "What is your age?:");

    //convert string to a number
    double num1 = Double.parseDouble(enterNum);

    JOptionPane.showMessageDialog(null, "Howdy youngster!");
    JOptionPane.showMessageDialog(null, "Howdy, you're on your way!!");
    JOptionPane.showMessageDialog(null, "Howdy, you're a mover and a shaker!");
    JOptionPane.showMessageDialog(null, "Howdy, old timer!");






























    }


    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Need help with user input/output for GUI.

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help with user input/output for GUI.

    import javax.swing.*;
    public class L4_SimpleCalc
    {
    public static void main (String[] args)
    {
    JOptionPane.showMessageDialog(null, "The Old Man says:");

    //Read in a value
    String enterNum = JOptionPane.showInputDialog(null, "What is your age?:");


    int age;
    char text;

    if (age <= 12){
    text = "Howdy uoungster!";
    } else if (age >12 and <20){
    text = "Howdy, you're on your way!!";
    } else if (age >=20 and <40){
    text = "Howdy, you're a mover and a shaker!";
    } else if (age >=40){
    text = "Howdy, old timer!";
    } else {
    text = "too old";

    }


    }

  4. #4
    Junior Member
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help with user input/output for GUI.

    This still isnt right but im on the right track I need it to work like that. how do i enter a value and have it come out in GUI with the right message?

    Quote Originally Posted by Tctwins View Post
    import javax.swing.*;
    public class L4_SimpleCalc
    {
    public static void main (String[] args)
    {
    JOptionPane.showMessageDialog(null, "The Old Man says:");

    //Read in a value
    String enterNum = JOptionPane.showInputDialog(null, "What is your age?:");


    int age;
    char text;

    if (age <= 12){
    text = "Howdy uoungster!";
    } else if (age >12 and <20){
    text = "Howdy, you're on your way!!";
    } else if (age >=20 and <40){
    text = "Howdy, you're a mover and a shaker!";
    } else if (age >=40){
    text = "Howdy, old timer!";
    } else {
    text = "too old";

    }


    }

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Need help with user input/output for GUI.

    When do you set age? What do you do with enterNum?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Junior Member
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help with user input/output for GUI.

    Quote Originally Posted by KevinWorkman View Post
    When do you set age? What do you do with enterNum?
    im lost..bad. I just wanna be able to enter a number and have that number go to the correct statement. if you could guide me out a little bit it would be a better learning process.

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Need help with user input/output for GUI.

    If you figure out the answers to the question I asked you, you'll figure out why you're getting compiler errors.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Valid user input
    By ChristopherLowe in forum Java Programming Tutorials
    Replies: 1
    Last Post: June 21st, 2011, 04:53 PM
  2. Valid user input
    By ChristopherLowe in forum Java Code Snippets and Tutorials
    Replies: 1
    Last Post: June 21st, 2011, 04:53 PM
  3. User Input File Name
    By PineAppleKing in forum Java Theory & Questions
    Replies: 12
    Last Post: June 3rd, 2011, 10:23 AM
  4. Game requesting user input
    By Neo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 3rd, 2011, 10:00 PM
  5. User Input Loop
    By cfmonster in forum Loops & Control Statements
    Replies: 7
    Last Post: August 24th, 2009, 01:52 PM