0
I’m trying to create a program in Java Agenda, but when I leave the JOptionPane
configuring the Agenda Owner name, called from the main window, the entire application is closed.
String nome = "";
do{
nome = JOptionPane.showInputDialog(null, "Informe o proprietário da Agenda", "Cadastro de proprietário",WIDTH);
if(nome == null){
System.exit(0);
}
else if(nome.isEmpty()){
JOptionPane.showMessageDialog(null, "Campo não pode estar vazio!");
}
else{
Agenda agenda = new Agenda(nome);
JOptionPane.showMessageDialog(null, "A agenda do "+agenda.getNome()+" foi criada com sucesso!");
}
}while(nome.isEmpty());
I know the problem is in System.exit(0)
, but I don’t know how I could solve.
Is there any motivation to use a
do while
in that context ?– Pedro
Present a [mcve] so that it is possible to test the code,
– user28595
This form is very bad, there are other ways better and less repetitive than this, but you can not suggest anything better, without testing. Access the link above and provide a minimal example that allows us to test your code and simulate the problem.
– user28595
I’ll improve the code to make it easier
– Francisco Oliveira
@Franciscooliveira don’t forget the [mcve]
– user28595