Check showMessageDialog and showOptionDialog examples
here. Each returning an int as the result of the selection. Similarly, you can return an object or just a String or int from your dialogs. This way, you will not need to implement this on your application classes and this implementation will be hidden inside your JDialog implementation.
I am not sure how this is implemented in JDK. You might try looking at the source code of JOptionPane class. I tried to find source code of it but could not find it in a limited time..