Remember that null is a primitive in java. Check for that using an ==
Code:
// Nb I changed the function calls to print statements
// to save having to rewrite your functions!
public void lite(JFrame parent) {
for (int liteweight=0; liteweight<3; liteweight++) {
// Create lwfunction object
Object lwfunction = JOptionPane.showInputDialog(parent,
"What Weights the most inthe?", "Heaviest Weight",
JOptionPane.QUESTION_MESSAGE,null,
new String[]{"Weight +5 years","Weight +3 years",
"Initial Weight"},""
);
// If the Object is null/we had cancel pressed. Null is
// a primitive in java so we compare using == null
if (lwfunction == null) { // if its null
System.out.println("Got null/Cancel pressed");
// return from our function
return;
}
// We now know our object is not null.
if (lwfunction.equals("Weight +5 years")) {
System.out.println("lwfive()");
}
else if (lwfunction.equals("Weight +3 years")) {
System.out.println("lwthree()");
}
else if (lwfunction.equals("Initial Weight")) {
System.out.println("liw()") ;
}
}
System.out.println("Question()");
}
--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock:
http://charlieharvey.org.uk