So I am working on a program for school, and part of the assignment is to have a bunch of prompts for input pop up. I am using the JOptionPane, which inherently has an OK button and a Cancel button. Now, to make the program exit when they press cancel when the prompt is asking for a string, I have something like this:
firstName = JOptionPane.showInputDialog("Please enter your first name:");
if(firstName == null)System.exit(0);
But I also have to do the same thing for numbers I get as input, both Doubles and Ints. If I try the same thing, it throws an error saying The operator == is undefined for the argument type(s) double, null. So, what is the best way for me to check if they click Cancel when being prompted for a numerical value? Thanks for your help!
Edit #1
Here is the code for the JOptionPane getting a numerical value:
startDateMonth = Integer.parseInt(JOptionPane.showInputDialog("Please enter the start date month (1-12):"));