Joptionpane calling the screen Main

Asked

Viewed 80 times

0

Good evening, I believe this doubt is simple but I can not solve, I have a method that displays a message instructing the user in the filling of a Captcha, until then ok, the "problem" is that when I press OK on this Jdialog it automatically opens my main screen which is in another package.

private static boolean telaCaptcha() {
        JOptionPane optionPane = new JOptionPane("Digite o código abaixo e clique em 'Solicitar Certidão' aguarde retorno da consulta, pressione OK nesta janela e o processo seguinte será automatizado");
        JDialog dialog = optionPane.createDialog("ATENÇÃO!");

        dialog.setAlwaysOnTop(true);
        dialog.setVisible(true);

        return tela = true;
    }

1 answer

0


To display a jop you don’t need to instantiate it, just write

 JOptionPane.showMessageDialog(null, "Digite o código abaixo e clique em 'Solicitar Certidão' aguarde retorno da consulta, pressione OK nesta janela e o processo seguinte será automatizado", "Atenção", JOptionPane.WARNING_MESSAGE);

Another detail that can help you is instantiating a jDialog in your main frame.

Jdialog will pause the execution of your frame, until the jdialog itself receives some closing event (e.g., Dispose()), then it will return to its frame.

In Netbeans you have the option to create a jDialog (wherever you go to create classes etc.. ) and this dialog already comes with all the events and everything else created, greatly facilitating the manipulation of the same. It is like a frame, can be made checks and everything else inside it (because it is a class like all other things), this can be useful since from what I understand you need to open this jdialog for the user to fill a captcha, and then if right return to the main frame (I think that’s it).

additionally within the jDialog itself you could create get to receive methods in the frame if the user chooses to close the dialog without completing the captcha..

something like..

CaptchaDialog cap = new CaptchaDialog(null,true);
cap.setVisible(true);
if (!cap.getValidacao){
   //o usuario optou por fechar o dialog sem conluir o captcha
}else{
  //o usuario acertou o captcha
}
  • I only created the dialog because I needed setAlwaysOnTop method that is not applicable in Joptionpane.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.