Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-14-2008, 03:57 AM
Member
 
Join Date: Jul 2008
Location: Tashkent, Uzbekistan
Posts: 6
fthnm2005 is on a distinguished road
Send a message via Yahoo to fthnm2005
[SOLVED] Help in the Code, please!
Hello all: I need a help in this simple program, whcih is almost complete, but one more requirement:

This is a simple program to select and display the Maximum number among 3 numbers eneterd by the user, and display it along with the Sum and Product of them in ONE MESSAGE DIALOG, but in different lines. I was able to display with seperate mes.dial. windows, but can not figure it out how to incorporate it into JOptionPane method. Can someone help, please?

Here is the complete program:

Code:
import javax.swing.JOptionPane; public class MaxSumProduct { public static void main(String[] args) { //variable declaration String firstNumber, secondNumber, thirdNumber; int number1, number2, number3, max, sum, product; // firstNumber=JOptionPane.showInputDialog("Please, enter the first number: "); secondNumber=JOptionPane.showInputDialog("Please, enter the second number: "); thirdNumber=JOptionPane.showInputDialog("Please, enter the second number: "); number1=Integer.parseInt(firstNumber); number2=Integer.parseInt(secondNumber); number3=Integer.parseInt(thirdNumber); max=number1; sum=(number1+number2+number3); product=(number1*number2*number3); if(max<number2) max=number2; if(max<number3) max=number3; JOptionPane.showMessageDialog(null,"The Maximum is: "+max); JOptionPane.showMessageDialog(null,"The Sum is: "+sum); JOptionPane.showMessageDialog(null,"The Product is: "+product); System.exit(0); }//End method }//end class

Last edited by fthnm2005 : 07-14-2008 at 05:48 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-14-2008, 04:45 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 780
Nicholas Jordan is on a distinguished road
setMessage
JOptionPane (Java 2 Platform SE v1.4.2)
Code:
Object[] possibleValues = { "First", "Second", "Third" }; Object selectedValue = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.INFORMATION_MESSAGE, null, possibleValues, possibleValues[0]);
Handy for getting data, I eventually went to using a file.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-14-2008, 05:47 AM
Member
 
Join Date: Jul 2008
Location: Tashkent, Uzbekistan
Posts: 6
fthnm2005 is on a distinguished road
Send a message via Yahoo to fthnm2005
Quote:
Originally Posted by Nicholas Jordan View Post

Handy for getting data, I eventually went to using a file.
Thanks for the post. But I did not understand... I mean how do I incorporate your code into the whole program? Or did we misunderstand each other?

thanks!
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-14-2008, 06:43 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Could you explain a little more what your program is not doing correctly?
To have a multiline output, use the newline character in your message text: "line1\nline2";

Also read the API doc for all the different ways to use JOptionPane. And then write a program to use as many of them as you can to see how they each work.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-14-2008, 07:09 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
I think he is looking what Norm says, multiple lines on JOptionPane. Simply use new line characters as Norma explain. This is quite simple thing that you should try before asking more pal. If you know how to use multiple lines generally, why don't you try it here too.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-14-2008, 07:14 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 780
Nicholas Jordan is on a distinguished road
as Eranga clarifies Norm
Quote:
Originally Posted by fthnm2005 View Post
Thanks for the post. But I did not understand...
Eranga's clarification of Norm's efforts is correct.
Quote:
Originally Posted by fthnm2005 View Post
I mean how do I incorporate your code into the whole program?
What I did was grab some sample code from the documentation. What I think, mostly from memory but I am reasonalby sure, is do a new JDialogBox has to be setMessage() in constructor. Actually, what I think I did wrong was not to look at you code a little closer.

I was thinking the Dialog would have a set message method call, maybe it does not. The way you are doing it, to get the three numbers all in the same ( displayed window ) can be done two ways. One is to build a string of the three numbers. The other, essentially the same, is to put all three numbers in one string.

Code:
package demo; // Constructs a string builder initialized to the contents of the specified string. class HelpTheCode { String str = new String("The maximum is: "); static final String lineSeparator = System.getProperty("line.terminator");// StringBuilder showEm = StringBuilder(str) ; showEm.append(number1.toString()); showEm.append(lineSeparator);// showEm.append(("The number is: "); showEm.append(number2.toString()); showEm.append(lineSeparator);// showEm.append(("The product is: "); showEm.append(number3.toString()); }
See line separator : Java Glossary

If you are using this in a organized study enviornment the instructor will spot the use of static final line ending and know that you have been getting help. Instead of doing that, you can use "\n" to separate the strings, but it does not work as well. See the cited link.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-15-2008, 01:47 AM
Member
 
Join Date: Jul 2008
Location: Tashkent, Uzbekistan
Posts: 6
fthnm2005 is on a distinguished road
Send a message via Yahoo to fthnm2005
Thank you all very much! Helped a lot!
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 07-15-2008, 05:49 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Nice, if you solve the question place mark the thread resolved. It's really helpful to all of us.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
my first jsp code munna_dude JavaServer Pages (JSP) and JSTL 1 04-29-2008 11:14 AM
I need help fixing my code.. or non code? MrHuggykins New To Java 1 03-20-2008 12:12 AM
code help chitwood New To Java 0 02-10-2008 02:08 AM
tic tac toe code zoe New To Java 1 07-23-2007 06:36 PM
Generating Code Automatically Using Custom code Template In Eclipse JavaForums Eclipse 1 04-26-2007 05:52 PM


All times are GMT +3. The time now is 12:55 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org