Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-10-2012, 05:17 PM   PM User | #1
BillyPerron
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
BillyPerron is an unknown quantity at this point
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..
BillyPerron is offline   Reply With Quote
Old 10-10-2012, 06:43 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
BillyPerron (10-10-2012)
Old 10-10-2012, 08:01 PM   PM User | #3
BillyPerron
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
BillyPerron is an unknown quantity at this point
Thank you for the response I will try and this and get back to you with results
BillyPerron is offline   Reply With Quote
Old 10-11-2012, 03:17 AM   PM User | #4
BillyPerron
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
BillyPerron is an unknown quantity at this point
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?
BillyPerron is offline   Reply With Quote
Old 10-11-2012, 04:57 AM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
\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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
java, joptionpanel

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:55 PM.


Advertisement
Log in to turn off these ads.