I\'m just learning Java exception handling and Java in general. I\'ve made a Swing GUI where the user will enter integers into two fields and then click a radio button with an
You'll get exception if you won't check your every event method, so you can do something like that to solve it,
private void aRadioButtonActionPerformed(ActionEvent evt) {
String a = aTextField.getText();
String b = bTextField.getText();
// you may get empty string here so check if the texbox is empty ?
int i=0,j=0;
try{
if(a.length()>0 || b.length()>0){
i = Integer.parseInt(a);
j = Integer.parseInt(b);
}else{
if(a.length()<1 && b.length()>0){
i = Integer.parseInt(a);
}else{
if(b.length()<1 && a.length()>0)
j = Integer.parseInt(b);
}
}
int k = i + j;
}catch(Exception e){
System.out.println("Exception:"+e);
}
cTextField.setText(Integer.toString(k));
}
do the same thing for you -,*,/ radio button listeners too