I have a series of of JOptionPanes pop up to get info from the user. However, if the user presses cancel, the machine gets an error (which is prevented). I'm trying to catch this and force the user to make a choice and press OK. MY code doesn't seem do do this. Here are the two ways that I tried:
//Obtians student information from the user
Object[] possibilities = {"AP Computer Science", "IB Computer Science", "Algebra II"};
StudentClass = (String)JOptionPane.showInputDialog(All, "What class is \nthe new student in?", "Info", JOptionPane.PLAIN_MESSAGE, null, possibilities, "IB Compter Science");
newStudent= (String)JOptionPane.showInputDialog(All, "Please enter the full name\nof the new student.", "Info", JOptionPane.PLAIN_MESSAGE);
newGrade= (String)JOptionPane.showInputDialog(All, "Please enter the grade\nof the new student.", "Info", JOptionPane.PLAIN_MESSAGE);
while (StudentClass.equals(null))
{
StudentClass = (String)JOptionPane.showInputDialog(All, "What class is the student whose\ngrades are to be changed in?", "Info", JOptionPane.PLAIN_MESSAGE, null, possibilities, "IB Compter Science");
}
and
//Obtians student information from the user
Object[] possibilities = {"AP Computer Science", "IB Computer Science", "Algebra II"};
StudentClass = (String)JOptionPane.showInputDialog(All, "What class is \nthe new student in?", "Info", JOptionPane.PLAIN_MESSAGE, null, possibilities, "IB Compter Science");
newStudent= (String)JOptionPane.showInputDialog(All, "Please enter the full name\nof the new student.", "Info", JOptionPane.PLAIN_MESSAGE);
newGrade= (String)JOptionPane.showInputDialog(All, "Please enter the grade\nof the new student.", "Info", JOptionPane.PLAIN_MESSAGE);
while (StudentClass.equals("null"))
{
StudentClass = (String)JOptionPane.showInputDialog(All, "What class is the student whose\ngrades are to be changed in?", "Info", JOptionPane.PLAIN_MESSAGE, null, possibilities, "IB Compter Science");
}
can some one show me the proper way to do this? Thanks!