For a Java college task, I have to create a dialog box that contains a form field using the MVC observer pattern.
I see from this post that I'm unable to attach an event listener to the ok button.
Add actionlistener to a button in joptionPane (java)
I'm only just starting to learn Java for the purpose of this course but from what I understand, the listener should be in the controller which should then update the model.
I'm therefore confused about how to pass the value of form field to the controller if I'm only able to access the data from the result of the button click like so:
int option = optionPane.showOptionDialog(frame, spinner, "Create a new alarm", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);
if (option == JOptionPane.OK_OPTION) {
...
Should I just update the model directly from the view or am I missing something?
Alternatively, I tried creating a custom button inside the dialog but I was unable to close the dialog after the button was clicked because the dialog was outside the scope of the listener.
We're not using Spring.