Reputation: 9
I am trying to make dialog show the all answers in one dialog but in multiple lines and I got no idea because after I add \n
it show \n
in the line too here is my code (I just deleted \n
line as it doesn't work at all)
Scanner keyboard= new Scanner (System.in);
int firstnumber= Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the first number"));
int secondnumber= Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the second number"));
int minus= firstnumber - secondnumber;
int sum= firstnumber + secondnumber; //sum the first number and second number
JOptionPane.showMessageDialog (null,"" + firstnumber + " + " + secondnumber + " = " + sum + ""+firstnumber+"-"+secondnumber+"="+minus, "Result", JOptionPane.INFORMATION_MESSAGE);
Upvotes: 0
Views: 83
Reputation: 664
You could use this:
public static String newline = System.getProperty("line.separator");
Then type newline in the string to add a newline.
Upvotes: 0
Reputation: 747
I think the text needs to be in a multiline container, such as JTextArea, otherwise it's just interpreted as plain text.
See http://docs.oracle.com/javase/tutorial/uiswing/components/textarea.html for implementation
Upvotes: 0