aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Internal Frames Problems...need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Internal Frames Problems...need help" Watch "Internal Frames Problems...need help" New topic
Author

Internal Frames Problems...need help

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jul 11, 2001
Posts: 15300
    
    6

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


GenRocket - Experts at Building Test Data
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jul 11, 2001
Posts: 15300
    
    6

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

Joined: Nov 22, 2008
Posts: 18944
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Internal Frames Problems...need help