in some java books I've read, I read that when closing a second frame that's on top of a main frame by using the x button in the upper right corner, a windowlistener event needs to be written to dispose that second frame. But I've noticed that when I just click the x on the second frame, it just closes the frame, not the main frame. This has me puzzled; do I really need to write a dispose for that frame?
Have look in the API for JFrame#setDefaultCloseOperation(int) and you see you can set a default operation on a JFrame. The API lists the 4 possibilities. EXIT will close all frames and all other operations, and is probably too vicious for an application which needs file writing, database access, etc.
From what you say, you can probably simply use DISPOSE with that method.
More of a Swing-related question, so I shall move this thread.
Let's say I have a second JFrame on top of a main JFrame. I want to close the second frame without closing the app. A couple of books mention that the second window's x (close) button needs to be programmed to be able to close it. But what I noticed is that the window just closes by clicking x without programming it. So, is it really necesary to program the close button?
Wouldn't you be better off having a JDialog sitting above the main JFrame rather than a second JFrame? Then there is absolutely no danger of closing the app when the dialog closes, you can better control modality type, and you can guarantee that the subwindow always sits above the main one.
This leads me to ask another question, though. I have a JFrame with a couple of buttons on it. I use a 1/3 of a MVC pattern on it - with that I mean that I implement VC, not the model. I think this also is called the strategy pattern. When somebody clicks on a button, an anonymus inner class in the "view" gets called and forwards it to the "controller". But now I want pop up a new JDialog box which also has a controller. My question is this; should the new JDialog and the controller be wholly instantiated within the method in the controller for the JFrame? Or should the be reference variables on a class level in the controller? I can't seem to figure out what is the best solution and any help would be appreciated!
Actually, I did put a new thread, it was one of the two you moved over here. But it wasn't getting any response and is drifting down the list. I thought I might as well put it in here as it seemed people regularly looked and responded.