A frame and a dialog
Say I have a JFrame with a button in it. I want a JDialog to appear when I click the button.
I could do this by writing another class that creates the JDialog and then by making an object of that class from my main class with the JFrame. But could I not also just create the JDialog in the original class? It wouldn't look very nice obviously; the JDialog is about 40 lines long. Is that the only reason for not wanting to do so?
My question is, should you separate code into classes for purely 'aesthetic' seasons?
If the dialog were simple and quite obviously dependent on the calling class, and also obviously that this will not change in the forseeable future, then I don't see any problem with keeping the code within the calling class if the class isn't too big. otherwise, it would be better to place the other GUI code in another class.
A note here though: I almost always create the JDialog object itself in the calling class since this creation usually needs to be controlled by the calling class, but I place the code that creates the JPanel that will serve as the JDialog's contentPane in its own class.
Will in my case it will make it slightly simpler because I need to access data from JTextFields in the JDialog...