Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help with JOptionPane (Im a Java newbie)

    Hello, I am enrolled in a entry level Java class and I have been doing a HW assignment and I was wondering if it was possible to make my Jpanel display multiple entries, for instance,
    Code:
     JOptionPane.showMessageDialog(null, "Class Grades Counted" +gradeCounter,  
        			  "Class Average Totals", 
        			  JOptionPane.INFORMATION_MESSAGE );
    This is the current segment of code that I have created within my program, when I run the program it displays the total number of grades inputted from a previous user prompt. However in my professors parameters for the assignment he wants us to also display the average as well as a possible switch/if statement for letter grades.

    What I tried to do was

    Code:
    JOptionPane.showMessageDialog(null, "Class Grades Counted" +gradeCounter,
                                             "Class Average" +total/gradeCounter,
                                             "Class Average Totals", 
        			  JOptionPane.INFORMATION_MESSAGE );
    Obviously this didn't work out so well, as I got compile errors.

    So what im asking is how do I get the one JOptionPane to display multiple things?
    Last edited by BillyPerron; 10-10-2012 at 06:34 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    That won't compile as it doesn't match the expected input for the signature showMessageDialog (showMessageDialog(Component, Object, String, int) is what you want to give it).
    Separate the two input messages with a +, not a comma. Then add \n to the start of the Class Average string, and it will add the linefeed.

  • Users who have thanked Fou-Lu for this post:

    BillyPerron (10-10-2012)

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you for the response I will try and this and get back to you with results

  • #4
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    I tried what I thought was your solution

    Ok so I took what I believe to be the soultion and did this
    Code:
     JOptionPane.showMessageDialog( null, "Class Grades Counted " + gradeCounter 
        			  + \n "Class Average" + total/gradeCounter,
        			  
        			  "Class Average Totals", 
        			  JOptionPane.INFORMATION_MESSAGE );
    When I do this the eclipse environment tells me "Sytax error on tokens, delete these tokens", What did i do wrong?

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    \n needs to be parsed as a part of the string for "Class Average".
    It should work nicely after you move that into the string.


  •  

    Tags for this Thread

    Posting Permissions

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