Sorry if this is obvious, but I haven't done this before.
I've made a JFrame subclass that, upon the user clicking the Input button on the main GUI, will pop up and allow the user to enter some data, after which the user clicks OK or Cancel to return that data to the main GUI.
Sounds easy enough, but how to implement it? The button on my main Frame can call a method to create the pop-up instance of a JFrame subclass that I've called InputFrame, but how to get the data back, when the user clicks the "Done" button?
I could pass a reference (
this) to the InputFrame which could be stored as a private variable and used to invoke a method on the GUI when the user hits Done. But this isn't exactly the same as just returning the data I need to the method that called it. And doesn't seem like good encapsulation, since I need to hard code into the InputFrame the name of the method in the GUI I want to use to handle the value returned. Whereas perhaps I want to access this data from several different places for different purposes (OK, I don't, but you see what I mean). There must be a standard way to do this - any pointers? Thanks.