Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFrame vs JInternalFrame

 
Arun Martin
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have designed a JMenu. On clicking each JMenuItem, a JInternal FRAME is invoked (because only JInternal Frame sits perfectly under JMenu). I have a button in the JInternal Frame which on invoked should open another JInternalFrame. I don't think it is possible
I tried invoking JFrame from JInternalFrame. The JFrame was opened but an exception was thrown so I rejected that idea. Is there any other alternative?.
with warm regards,
Arun.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't you open another JInternalFrame? If you have the reference to your controlling window just create another one.
 
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
Ok, I had that problem at one time too. But I figured out how to do it.
It is something like this:

And then you have a another class file that is your internal frame and you call it anInternalFrame.java
Then from any other internal frame, all you have to do is call the openTheFrame() method and a new window will open.
I know this is kind of crude, but I think it is enough to get you going. Let me know if you need more help.

------------------
Happy Coding,
Gregg Bolinger
 
Arun Martin
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks a lot for the responses. I tried some twiddling of my own with help from ur queries. I am happy to say that I have acheived the desired result. I am here giving out the rough analysis of the code. Before that I would like to state what I precisely I need. I have designed a JMenu and on clicking each JMenuItem,the first JInternalFrame is opened and when a button is clicked a second JInternalFrame should be opened. This is how I went about it
1. Declared a JFrame containing a static Desktop and containing the JMenuItems. On clicking a particular JMenuItem, the first JInternalFrame is opened
public class MainFrame extends JFrame
{
static JDesktopPane desktop;
MainFrame()
{
MenuItem.addActionListener(new ActionListener()
{
InternalFrame1 fr1 = new InternalFrame1();
// invoking the first JInternalFrame
desktop.add(fr1);
fr1.setVisible(true);
fr1.show(true);
}
}// end of constructor MainFrame
} // end of class MainFrame
2. Declaring the the first JInternalFrame,and inside when a button is clicked a second JInternalFrame should be opened
public class InternalFrame1 extends JInternalFrame
{
InternalFrame1()
{
super("title",false,true,false,false);
this.setFrameIcon(null);
// remaining code
}// end of constructor InternalFrame1

public void actionPerformed(ActionEvent evt)
{
InternalFrame2 fr2 = new InternalFrame2();
// invoking the second JInternalFrame
fr2.setVisible(true);
MainFrame.desktop.add(fr2);
fr1.show();

}// end of actionPerformed
} // end of class InternalFrame1
3.The second JInternalFrame2
public class InternalFrame2 extends JInternalFrame
{
InternalFrame2()
{
super("title",false,true,false,false);
this.setFrameIcon(null);
// remaining code
}// end of constructor InternalFrame2
} // end of class InternalFrame2

with warm regards ,
Arun.





 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic