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.


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

Results 1 to 2 of 2

Thread: Beginner Java issue

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Thanked 0 Times in 0 Posts

    Default Beginner Java issue


    I am trying to figure out how to use the GUI to input an integral, perform a calculation with the input data, and display it in a message box. For example, input weight in kilograms and display weight in pounds.

    The problem I am having is with respect to JOptionPane.showMessageDialog. Am I not allowed to display via dialog box using this method?

    import javax.swing.JoptionPane;
     public static void main(String[] args)
        double weightK;
        double weightP;
        String weightKstr;
        String weightPstr
        #prompt user to input their weight in kilograms
        weightKstr = JOptionPane.showInputDialog
                ("Enter your weight in kilograms: ");
        weightK = Double.parseDouble(weightKstr);
        # The conversion
        weightP = (weightK * 2.2);     
        weightPstr = "Weight: " + weightP + "pounds";
        # Displays the weight in pounds in a plain message dialog box     
        OptionPane.showMessageDialog(null, weightPstr, "conversion",

    Thanks in advance!

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 698 Times in 680 Posts

    Default Re: Beginner Java issue

    What language are you writing this in? If Java, where did you learn a comment begins with '#'? I'm glad (tickled pink, actually) that you're actually using comments, but do them correctly. And did you know that Java is case sensitive?

    Why isn't your main() method in a class?

    Certainly, your problems, whatever they are, have very little to do with JOptionPane (check your typing) and with typos, bad comment symbols, no enclosing class, etc.

    Fix those errors and come back if you still need help.

Similar Threads

  1. Beginner's Looping Issue
    By JamesJillum in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 23rd, 2013, 08:07 AM
  2. Beginner assignment - constructor issue / error
    By Jarruda in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 21st, 2012, 01:29 AM
  3. ArrayIndexOutOfBoundsException issue (Beginner?)
    By cziiki in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 15th, 2012, 07:12 AM
  4. Beginner trying to write Java code, has issue w/ printing result and 2 decimals
    By flpanthers1 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 5th, 2011, 11:11 AM
  5. Issue with beginner program
    By suxen in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 5th, 2011, 08:55 AM