0
I have two variables:
int trabalhadorFormal;
int dispensadoIndireta;
And I’m wearing them JOptionPane.showConfirmDialog
to confirm as a kind of Boolean, yes or no, for the user.
trabalhadorFormal = JOptionPane.showConfirmDialog(null,
"É trabalhador formal?",
"Por favor selecione",
JOptionPane.YES_NO_OPTION);
dispensadoIndireta = JOptionPane.showConfirmDialog(null,
"Foi dispensado indiretamente?",
"Por favor selecione",
JOptionPane.YES_NO_OPTION);
And with this I have the following code:
if (trabalhadorFormal == JOptionPane.YES_OPTION) {
if (dispensadoIndireta == JOptionPane.NO_OPTION) {
do {
opcao = Integer.parseInt(JOptionPane.showInputDialog("[1] - É empregado doméstico" +
"\n[2] - Não é empregado doméstico"));
switch (opcao) {
case 1:
JOptionPane.showMessageDialog(null, "É empregado doméstico!");
break;
case 2:
JOptionPane.showMessageDialog(null, "Não é empregado doméstico!");
break;
default:
JOptionPane.showMessageDialog(null, "Opção inválida!");
break;
}
} while (opcao != 1 && opcao != 2);
} else {
JOptionPane.showMessageDialog(null, "Teste!");
}
}
The only problem is that when I select the options that will lead me to the else
after the second if
, nothing happens and the program closes me by returning successfully, as simply ignoring the else
.
What is going wrong here? In building the if-else
?
What the Bugger says about the value of
dispensadoIndireta
?– Oralista de Sistemas
I replicated your code here and it worked right, according to your code if you choose not it enters your do while, and while if you indicate a valid condition it breaks and exits the loop. In the second if you give a yes it goes to the Else and prints test.
– Edjane