• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Internal Frames Problems...need help

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I've been having major problems with getting internal frames working when used over multiple classes in different files. Basically, I have a control program which has options when clicked should open a new internal frame in the desktop pane.
At the moment I'm having trouble opening a new internal frame when the code is in a separate file. file J1 opens an internal frame in a desktop pane and file J2 should open another Internal frame but it displays nothing. I don't know why, I've tried everything I can think of but it won't work.
Has anyone got internal frames to work over multiple classes ?
The code:
----------------------------
file J1:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import J2;

public class J1 extends JFrame {

public static void main(String[] args) {
new J1();
}
public J1() {
super("JInternalFrames Test");

Container content = getContentPane();
content.setBackground(Color.white);
JDesktopPane desktop = new JDesktopPane();
desktop.setBackground(Color.white);
content.add(desktop, BorderLayout.CENTER);
setSize(450, 400);
for(int i=0; i<1; i++) {
JInternalFrame frame
= new JInternalFrame(("Internal Frame 1" + i),
true, true, true, true);
frame.setLocation(i*50+10, i*50+10);
frame.setSize(200, 150);
frame.setBackground(Color.white);
desktop.add(frame);
frame.moveToFront();

}
new J2();
setVisible(true);

}
}
-------------------------------
file J2:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import J1;

public class J2 extends JInternalFrame{
public static void main(String[] args) {
new J1();
}
public J2() {

//Container content = getContentPane();
//content.setBackground(Color.green);
JDesktopPane desktop = new JDesktopPane();
desktop.setBackground(Color.green);
//content.add(desktop, BorderLayout.CENTER);
//frame.setSize(450, 400);

JInternalFrame frame = new JInternalFrame("InternalFrame 2", true, true, true, true);
frame.setLocation(50+10, 50+10);
frame.setSize(200, 150);
frame.setBackground(Color.green);
desktop.add(frame);
frame.setVisible(true);


}
}
--------------------------
Any ideas are much apppreciated.
Suhail
 
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
Hi, what I did was, I created a Class that is my DesktopPane(). And I used that class to fire my multiple internalframes. So every other Internalframe I have is in it's on Class file. So here is some Psuedo to maybe help.


Now here is the Class for the InternalFrame

I hope that is enough to get you started. Remeber, quite a few variables will have to be GLOBAL so that all classes can see them so static is a good thing to do in most cases. At least that's what I have found.
Good Luck!!

------------------
Happy Coding,
Gregg Bolinger
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying
I tried to use your code which looked good but I keep getting a nullpointer exception when running the app. If I take out a refrence to execute method IFrame1() it brings up the desktoppane and nothing else and no error. but as soon as I try to execute the IFrame1 method I get a null pointer exception.
I'm beginning to think its impossible to use internalframes for any kind of app. Maybe I'll try to update my copy of the JFC swing or the JDk (I currently have version 1.2.1).
It seems like it should be easy but its not.
Any further ideas ???
Suhail Sarwar
 
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
I'm not sure why you are getting a null pointer. My code was rough, and should not have been coppied and pasted and used. I was just outlining the methods for you. Internal Frames CAN be used for Apps. That is all I use for my Apps that I create. I have had no problem. It just took me some time to get the feel of them.
Could you post some of your code so that I can take a look? Also, put them in the CODE tags so that it looks better.
Good Luck.

------------------
Happy Coding,
Gregg Bolinger
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code I am using for the 2 files is:

The second file is......

I hope you can spot where the problem is.
Thanks for your help.
Suhail
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic