Hey guys.
I have multiple System.out.println, 7 to be precise. The last 4 are in a if, else if, else statement. How can I put all of this into one dialog box?
Thanks in advanced.
Curtis H.
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.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hey guys.
I have multiple System.out.println, 7 to be precise. The last 4 are in a if, else if, else statement. How can I put all of this into one dialog box?
Thanks in advanced.
Curtis H.
Are you asking how to write some lines of code in a method in a class that extents the JDialog class?
Otherwise can you explain and post some code showing what you are trying to do.
If you don't understand my answer, don't ignore it, ask a question.
This is the end of my code. It is for some sort of calculator. The only thing I am struggling with is "outputting it to a dialog box instead of having it output at the bottom of the eclipse screen".
System.out.println("The length of your building (in metres) is: " +length); System.out.println("The width of your building (in metres) is: " +width); System.out.println("The amount of weight you want to bring (kilograms) is: " +stock_coming); System.out.println("The amount of weight you are allowed to have per square metre (kilograms) is: " +stock_allowed); System.out.println("\nThe area of your building is: " + area + " metres squared" ); System.out.println("The total weight you can have is: " + enough + " kg"); System.out.println("The total weight you are trying to deliver is: " + stock_coming + " kg\n"); // if else statements if ( stock_coming > enough) System.out.println("You would be exceeding your weight allowance!"); else if ( stock_coming == enough) System.out.println("You have exactly the right amount!"); else System.out.println("You have more than enough room!");
I would like to output this inside a dialog box instead of it just appearing at the bottom of the screen. I can do the first 7 system.out lines, but I have no idea how to put the "if, else if, else" statement into one of these boxes. Just to clarify I would like it all in one dialog box. the JOptionPane one, with the INFORMATION_MESSAGE icon.
Thanks in advanced
Curtis H.
Have you tried to send the text to a JOptionPane? If so, show us that code. If not, start by thinking that all text currently being sent to the println() methods will instead be sent to a JOptionPane method, and program that. From that thinking and coding experience, you should see that the if/else logic is irrelevant to WHERE or HOW the text is being displayed. It's program logic that decides WHAT is being displayed not HOW or WHERE it is being displayed.
When building the String to be displayed in the dialog, the if statements can be used to control what text is added to the String that is being built:how to put the "if, else if, else"At the end of the above, theText will contain the String to be shown in the dialog.String theText = "First part"; if(wantThisP) { theText += "thisP"; }else{ theText += "thatP"; }
If you don't understand my answer, don't ignore it, ask a question.
Norm's response helped me understand your question better. If you're constructing the String object from parts before sending it to a JOptionPane method for display, I recommend using an instance of StringBuilder in which to construct the message.
I'm struggling to understand how I put the 7 lines of text (systemout) and the other statements in the same one box. Am I wrong to say if I put JOptionPane for each time I've put System.out, won't it just open multiple boxes, instead of one box with all the information?
Combine all of the Strings into one (using StringBuilder, if you'd like) and output them to the JOptionPane method once. Now struggle with some code.
iCurtisIT (November 29th, 2013)