Java Dialog - Find out if OK is clicked?

前端 未结 4 1663
一向
一向 2020-12-01 22:48

I have a dialog for a client-GUI that asks for the IP and Port of the server one wants to connect to. I have everything else, but how would I make it so that when the user c

4条回答
  •  执笔经年
    2020-12-01 23:16

    I'd suggest to use showConfirmDialog instead

    int result = JOptionPane.showConfirmDialog(myParent, "Narrative", 
           "Title", JOptionPane.INFORMATION_MESSAGE);
    

    and there you can test for various returns value from JDialog/JOptionPane

    if (result == JOptionPane.OK_OPTION, 
                  JOptionPane.CANCEL_OPTION, 
                  JOptionPane.CLOSED_OPTION, etc..
    

提交回复
热议问题