I want to show a dialog box, click the yes button and then continue to jump out of the next dialog box, click the no button to jump out of the tips dialog box prompt to click the yes button, press this loop, now I can use if nesting to achieve, I would like to ask if there is a better way to achieve this, such as recursive what?
part of the code is as follows:
//add yesbutton and yesbutton_actionlistener
frame.add(yesButton);
yesButton.addActionListener(e -> {
int resbonse1 = JOptionPane.showOptionDialog(null, "questionOne", "infinityLove",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
null, null, null);
if (resbonse1 == JOptionPane.NO_OPTION) {
JOptionPane.showOptionDialog(null, "please click yes", "tips",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
null, null, null);
}
//click yesbutton in the first dialog
if (resbonse1 == JOptionPane.YES_OPTION) {
int resbonse2 = JOptionPane.showOptionDialog(null, "questionTwo", "infinityLove",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
null, null, null);
if (resbonse2 == JOptionPane.NO_OPTION) {
JOptionPane.showOptionDialog(null, "please click yes", "tips",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
null, null, null);
}
//click yesbutton in the second dialog
if (resbonse2 == JOptionPane.YES_OPTION) {
...
}
}
}