public static void main(String args)
A gui=new A();
public void actionPerformed(ActionEvent evt)
B gui2=new gui(); // B here is another GUI using Jframe
So when the an event is performed in the first frane and another gui is invoked, there will be 2 windows in total. So when we close the newly created one(in this case gui2) the older one also atomatically gets closed.. Is there anyway to make both these windows independent?
Is there anyway to make both these windows independent?
Yes, but not without A.java starting a completely new Thread which would call B.java's main method. You can make it so that closing B.java doesn't end A.java by using dispose() instead of a System.exit for B.java. But once A.java die, B.java will also die.
What is your purpose in making them completely separate? What are you trying to achieve. Maybe we can give you a better alternative?
karthick Soundararaj wrote:Thanks for the prompt replies.
Is that the only solution?
No, you could also do something like Runtime.exec("somefile") where somefile is a batch file or shell script that kicks off the other Java application (B). Keep in mind that your frames won't really be able to communicate with each other as they will both be in their own VM.
Joined: Mar 09, 2009
Ok.. Thanks a lot, but i would be great if the future versions of java brings in a better solution for making them independent.. If you come across any other solution do post it here...
karthick Soundararaj wrote:Ok.. Thanks a lot, but i would be great if the future versions of java brings in a better solution for making them independent.. If you come across any other solution do post it here...
Why would that be great? I don't use any applications that work this way. Applications should encapsulate themselves into a finite set of frames that all belong to the same VM, IMHO.
I think it can be all a lot simpler. What happens when you close your frame B? Does it exit? In other words, have you somewhere written
If so, then it is just logical that closing frame exits the entire application. If you change the EXIT_ON_CLOSE to DISPOSE_ON_CLOSE your application should only be closed completely if all non-daemon threads exit - and the EDT thread won't exit because there is still a frame active.