2
In the system there is a field, the person needs to fill this field and then press enter.
By pressing enter the system does a check and then opens a JOptionpane
asking to select: yes, nay, okay, etc..
The person presses enter, and the system performs the function, so far everything ok.
The problem is: by pressing enter on JOptionPane
(for example pressed enter on the button yes) it performs the function again, but as it was not filled the system ends up accusing an error, then it gets in the loop, because the person who uses the system presses enter, then it loads again, and so it goes...
How to get around this? I’ve tried several things, I’ve searched the internet several things, everything without success has something to do to fix it?
To capture the action, I’m using KeyListener
EDIT 1:
try {
if (evt.getKeyCode() == 10 || evt.getKeyCode() == 127) {
jfObjeto.setText(jfObjeto.getText());
controller.getAtendimentoController().novoAtendimentoItem();
controller.getAtendimentoController().getAtendimentoModel().getAtendimentoItem().setObjeto(jfObjeto.getText());
}
if (evt.getKeyCode() == 10) {
//verifica se possui sigla cadastrada
controller.getAtendimentoController().verificaCampoObjeto(
controller.getSistemaOperacaoController(),
controller.getSistemaSiglaEtiquetaController());
//verifica se o objeto possui lancamento para EDITAR
controller.getAtendimentoController().consultaObjetoEdicao();
if (controller.getAtendimentoController().getAtendimentoModel().getAtendimentoItem().getId() > 0) {
int resposta = new Mensagem().pergunta("Atenção deseja alterar o objeto " + controller.getAtendimentoController().getAtendimentoModel().getAtendimentoItem().getObjeto() + "?");
if (resposta == 0) {
preencherAtendimentoItemToFrame();
}
}
// avanca para proximo campo, ou recua para o anterior
formatarAvancarRecuarAtendimentoItem(evt, jfObjeto);
} else if (evt.getKeyCode() == 127) {
controller.getAtendimentoController().consultaObjetoEdicao();
if (controller.getAtendimentoController().getAtendimentoModel().getAtendimentoItem().getId() > 0) {
int resposta = new Mensagem().pergunta("Deseja excluir o objeto " + controller.getAtendimentoController().getAtendimentoModel().getAtendimentoItem().getObjeto() + "?");
if (resposta == 0) {
controller.getAtendimentoController().excluirObjetoPostagemItem();
controller.getAtendimentoController().carregarListaAtendimentoItem();
tabelaAtendimentoItem();
limparAtendimentoItem();
carregarQuantidadeValorTotalAtendimento();
controller.getAtendimentoController().novoAtendimentoItem();
jfObjeto.requestFocusInWindow();
}
} else {
new Mensagem().erro("Nenhum Objeto Localizado para Exclusão");
}
} else if (evt.getKeyCode() == 27) {
formatarAvancarRecuarAtendimentoItem(evt, jfObjeto);
}
} catch (Exception ex) {
new Mensagem().erro(ex.getMessage());
jfObjeto.requestFocusInWindow();
}
Post the code of
KeyListener
so we can help you.– Jéf Bueno
It would not be easier to let open such JOPTIONPANE only and only if the necessary field(
No sistema existe um campo, a pessoa precisa preencher este campo e em seguida pressionar enter.
) is different fromnull
orvazio
etc. :)– jsantos1991
I don’t understand the technology but my first idea would be to shift the focus to somewhere else before opening the PANE.
– RSinohara
is different from null or empty etc :) - If null the message informs that the user needs to enter this field.... then he’s squeezing enter all the time and enters the loop I said....
– HimorriveL
falls into the same error, I take the focus run the command at the end it gets the focus again for the user to type other information... will fall into the eternal loop.... the problem is in ENTER that the person in JOPTION PANE, there due to this enter he enters the infinite loop.... EDIT: I need the key, because the enter has a function... the Esc has another function... the delete key has a function... can not be that too
– HimorriveL
There is the possibility to insert the Keylistener source?
– Renoir Reis
this inserted in the keyListener... the code that I put there.... because enter has a function... Esc has another function... the delete key has a function and I need to capture the event....
– HimorriveL
Has any response helped solve the problem and can address similar questions from other users? If so, make sure to mark the answer as accepted. To do this just click on the left side of it (below the indicator of up and down votes).
– Sorack