CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   Help with JOptionPane (Im a Java newbie) (http://www.codingforums.com/showthread.php?t=276037)

BillyPerron 10-10-2012 05:17 PM

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?

Fou-Lu 10-10-2012 06:43 PM

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.

BillyPerron 10-10-2012 08:01 PM

Thank you for the response I will try and this and get back to you with results

BillyPerron 10-11-2012 03:17 AM

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?

Fou-Lu 10-11-2012 04:57 AM

\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.


All times are GMT +1. The time now is 03:54 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.