There are two common approaches. The simple one, often used for dialogs, makes the selected values (e.g. your combobox selection) available for other classes, the second one allows other classes to register on your object to receive update notifications.
First approach
- store the actual selections of your GUI elements in (private) member variables (like:
private String currentSelection
). This is done by the listener that you already implemented.
- implement a method like
String getSelection()
- When the dialog is done (like someone pressed the OK button), fetch the value by simply calling the
getSelection()
method
This can be used if you offer a dialog for a user to enter some values. The file chooser dialogs are a typical example. If you require 'real time' access to the current selection, then use the:
Second approach
- Implement the Observer Pattern (Listener class, eventually an event class)
The pattern is a bit too complex to explain it step by step and in detail, but there's a lot of documentation and examples around, if you're interested and really need this realtime access to changes.