Skip to content
Advertisement

event when press exit button: JOptionPane.showInputDialog

How can I add a function after clicking on the cancel or exit button? I tried it like this but it doesn’t work for me.

It shows me an error that choice is null but it couldn’t be because it is int? is there any other possibility to solve it?

JavaScript

Advertisement

Answer

When you press the “exit” or “cancel” button, you are assigning “choice” to null, but that won’t work because choice is an int. You could make “choice” a String and then, before the switch statement, make sure choice!=null. This is what that would look like

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement