Lovin' java
Joshua Ebarvia wrote:I have 2 JFrames in my Application. The first JFrame acts as the main JFrame, simply put JFrame_main.
[url]http://FrancoisNadeau.com[/url]
At the center of non-violence stands the principle of love
.... Martin Luther King, Jr.
[url]http://FrancoisNadeau.com[/url]
pete stein wrote:Ramses and Francois: Does the OP's problem suggest the need for a dialog as the second window and not a JFrame? The second window is clearly dependent on the first, and a JDialog is the cleanest most straightforward way to enforce this dependency.
At the center of non-violence stands the principle of love
.... Martin Luther King, Jr.
Francois Nadeau wrote:Hello Pete,
I agree with you that a JDialog may be a better GUI design, but I do not know what the requirements are for this code.
Joshua asked why his JFrame was not displaying a second time. The answer to this question is that his "if" statement checked for a null value, yet he did not set his jframe_sub variable to null after disposing it. Using a JDialog will not resolve this problem.
pete stein wrote:
The answer here is not to check for null.
[url]http://FrancoisNadeau.com[/url]
Lovin' java
[url]http://FrancoisNadeau.com[/url]
Lovin' java
[url]http://FrancoisNadeau.com[/url]
Francois Nadeau wrote:Hi Joshua,
It mostly depends on how you want your application to behave. The way I understand your GUI design is that you will have a toolbar-like-window from which you can start and view other windows. I personally don't like that design because it creates many windows when I am using a single application. But that is my own personal preference, there are applications out there that follow this pattern (for example Gimp).
If you are asking my opinion, I would suggest using a JTabPane instead. This will allow you to split-up your application in different views, without having multiple windows. In other words, your users will have only one window to deal with.
An other option would be to use JInternalFrames. But again that is not one of my favorite approaches since users still have to manage a bunch of windows.
If you persist on wanting separate frames, then your on the right track but may have problems if the user closes your frames with the X button (or alt+F4 on windows) instead of your dispose button. To solve that you will need to look into JFrame's setDefaultCloseOperation function.
I am willing to further discuss your GUI design, but we will need to have more details. For example, what will your application do, who will use it, how many screens will it have, and what type of processes/activity will it perform.
Hope this helps.
Lovin' java
[url]http://FrancoisNadeau.com[/url]
Francois Nadeau wrote:Hi Joshua,
Ok, that make sense to me. You say that each of the applications were developed separately. That sounds a little worrisome to me.
1. Do any of the applications call System.exit()? If so then your current design will cause all windows to close when it is called.
2. What happens if one of the applications crashes? Is it OK for all of them to die?
3. Does the applications use static variables to store internal data. This will most likely prevent you from creating new instances of your application, since some data will be left behind from one execution to an other.
4. What kind of logic has been added to each of the application's JFrame.windowListeners? This could get messy....
I can think of two options to solve these problems,
1. Only allow one application to run at a time, and keep a reference to the ones that have been created (this is basically what you have been doing, but will need a little black magic if logic has been inserted in windowlisteners).
2. Start each of the applications as an external application (in which case the easiest thing to do would be to create a bunch of batch files and put them in the a start-application-folder, or if you really want to program something then use Runtime.exec()).
I think option 2 would be the best. It would require no programming, but may be a little annoying to deploy.
Hope this helps.
Lovin' java
Consider Paul's rocket mass heater. |