• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making instantiated frames independent

 
karthick Soundararaj
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, This is my first post. I have got this problem. Say there are two GUIs.

Class A extends JFrame implements ActionListener
{
A()
{
// all the code to create gui is here.
}

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?


 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i invoke the main function of other class. I understand that Main method is static and it should be invoke along with Class Name but what about the argument that has to be passed?

There is no purpose behind my question other than the urge to gain expertise
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't have any arguments, just pass it an empty array. Note this is untested code.



Something like that anyway.
 
karthick Soundararaj
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the prompt replies.


Is that the only solution?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
karthick Soundararaj
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic