Hi. Currently im using JOptionPane to create the program. This is the codes.
import javax.swing.JOptionPane;
public class Homework3
{
public static void main(String args[]){
int number;
String message1 = "Please enter the positive number"+ "\n";
String message2 = "Please enter the positive number, not negative number"+ "\n";
String message3 = "Please enter in numbers, not letters"+ "\n";
String num, outputMessage ;
try{
num = JOptionPane.showInputDialog(message1);
number = Integer.parseInt(num);
if (number<0)
throw new IllegalArgumentException();
outputMessage = "The number was"+ number ;
JOptionPane.showMessageDialog(null,outputMessage);
}
catch( NumberFormatException e)
{
JOptionPane.showMessageDialog(null,message3);
}
catch ( IllegalArgumentException e)
{
JOptionPane.showMessageDialog(null,message2);
}
System.exit(0);
}
}
The problem is, when I click the cancel button, it shows the message "Please enter in numbers, not letters". I'm so confusing that why the program shows this message and not closing when I click the cancel button. Also, the out put will shows in this way.
Lets say the output is 1234.
The number was 1234
The digits are
1
2
3
4
How do I allign the message in this way??? please help me!!!