JOptionPane issue
Hi all
I am using the following piece of code:
String tempnewoctet1 = JOptionPane.showInputDialog("Enter the first octet of the new subnet: ");
String tempnewoctet2 = JOptionPane.showInputDialog("Enter the second octet of the new subnet: ");
String tempnewoctet3 = JOptionPane.showInputDialog("Enter the third octet of the new subnet: ");
and i need to check that an input has been entered. If the user clicks CANCEL on this then NULL is assigned to the String variables and i can sucessfully test for this. However if the user just clicks OK without typing anything something is assigned to the variables but i don't know what!
I have tried printing out the variables but all i get is black space so i tested for " " but with no sucess. Does anyone know that this value is and how i can test for it (if it was a /0 for example)?
# 2
Well to test the value of the variables i am using:
if(newoctet1 == null || newoctet2 == null || newoctet3 == null
but this case only applies when the user clicks the cancel button. If they click the OK button but dont type anything then the variables aren't assigned a NULL value, they are assigned something else...but i dont know what, and i specifically need to test for that value
# 3
Well to test the value of the variables i am using:
You said "i tested for " " but with no sucess"... Note that "if (s == "")" or "if ("" == s)" are totally different tests to "if ("".equals(s))" or "if ((s != null) && s.equals(""))"
The default string will be empty, ie "".
A test which returns true if a string has content is: "if ((s != null) && (s.length() > 0))"
If you have formatting conditions which need to be met then you might want to use a regex (see the Pattern class) to check it, and/or use a JFormattedTextField.