I think the best option for you would be to use the following code
JTextField topicTitle = new JTextField(); JTextField topicDesc = new JTextField(); Object[] message = {"Title: ", topicTitle, "Description: ", topicDesc}; Object[] options = { "Yes", "No" }; int n = JOptionPane.showOptionDialog(new JFrame(), message, "", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if(n == JOptionPane.OK_OPTION){
using the showOptionDialog method, you get a result based on what the user is doing, so you donβt have to do anything except interpret this result
source share