I have created a method that will return true or false depending on the checkbox marked in a Jpanel. I will use that return to write Strings so that if the value is false it prints a message and if it is true another one.
public boolean estabilidad() {
boolean estable = false;
if (establecheck.isSelected() && hipoTAcheck.isSelected()) {
JOptionPane.showMessageDialog(null, "Estable no es compatible con HipoTA ");
} else if (establecheck.isSelected()) {
estable=true;
} else if (hipoTAcheck.isSelected()){
estable=false;
}
return estable;
}
When 2 checks coincide, as in the first If , a message appears stating that they are not compatible, but then the flow continues and returns false, so the program continues to print an incorrect message or one that is irrelevant.
How can I make it so that once this message appears, the program does not continue until the user unchecks the corresponding box?
The method that returns the Strings based on the boolean variable obtained is
public String mensajeEstabilidad(boolean estable) {
String mensaje;
if(estable==true){
mensaje="Paciente generalmente estable durante los tratamientos \ncon " +
"buena tolerancia a las sesiones y sin incidencias a reportar";
}else {
mensaje="Paciente inestable, con incidencias reportadas en cuanto a tolerancia \nde " +
"las sesiones. Manifestado con sintomatología asociada a la hipotensión";
}
return mensaje;
}
In the way that you tell me, this would be the solution that I see to stop the flow of the method and it is using an exception.
and outside of your method, where you are calling it you control the exception and incorporate what you want to do.