MDI Application - internal frame in seperate class

Hello everybody,

Before asking the question I want to say something. I am working in .NET since last three years. But now I want to migrate to Java , the main reason is platform independence. I have done a lot of projects in windows forms but started Swing this week only. This is my first question in any Java community, I am looking for good response.

Now I come to my question.

I am working on a MDI application swing using Netbeans 5.5.1. I am able to make a MDI app by using JDesktopPane and Internal frames but the problem is that I have to put all the code in one class(file) only. I want something like in windows form i.e. one file MDI.java and seperate files internal1.java, internal2.java etc so that I can display these internal frames using a Menu in MDI.java. I have searched a lot but could not find any solution so far.

Is there any solution? Kindly help.

P.S. - If you feel that I am not able to put the problem in good way feel free to ask further. As I have said I am new to Java, it will take time to understand things.

[1076 byte] By [Solankya] at [2007-11-27 8:28:43]
# 1
If the IDE is restricting your choices, ditch the IDE and code by hand.
kirillga at 2007-7-12 20:18:47 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks kirillg, but I am not facing any problem with the IDE. I am facing problem with the coding itself. The main problem is that how can I place the code of Internal Frame in separate class (not in the class where I have put the jDesktopPane).
Solankya at 2007-7-12 20:18:47 > top of Java-index,Desktop,Core GUI APIs...
# 3
Create a separate class and put the code for internal frame there. You can create as many classes as you want. I'm not sure that i understand the problem.
kirillga at 2007-7-12 20:18:47 > top of Java-index,Desktop,Core GUI APIs...
# 4

Where I've put the call to 'new JInternalFrame()' in the actionPerformed() method, you can put in a call to instantiate your own subclass of JInternalFrame (your subclass may be defined wherever).

Note JDesktopPane doesn't give you the nice stuff, like automatically positioning the internal frames, or a 'Windows' menu listing all the frames. You might find this link handy if you want that stuff:

http://www.javaworld.com/javaworld/jw-05-2001/jw-0525-mdi.html

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class JInternalFrameExample extends JFrame implements ActionListener {

private JDesktopPane desktop;

private int counter = 1;

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {

public void run() {

new JInternalFrameExample();

}

});

}

public JInternalFrameExample() {

setDefaultCloseOperation(EXIT_ON_CLOSE);

desktop = new JDesktopPane();

Container content = getContentPane();

JButton btnAdd = new JButton("Add Internal Frame");

btnAdd.addActionListener(this);

JMenuBar menu = new JMenuBar();

menu.add(btnAdd);

setJMenuBar(menu);

content.setLayout(new BorderLayout());

content.add(desktop, BorderLayout.CENTER);

Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

setSize((int) (screen.getWidth() * 0.75), (int) (screen.getHeight() * 0.75));

setVisible(true);

}

public void actionPerformed(ActionEvent e) {

JInternalFrame iFrame = new JInternalFrame("Internal Frame " + counter++, true, true, true, true);

iFrame.pack();

iFrame.setSize(new Dimension(300, 100));

iFrame.setVisible(true);

desktop.add(iFrame);

desktop.moveToFront(iFrame);

}

}

mbmerrilla at 2007-7-12 20:18:47 > top of Java-index,Desktop,Core GUI APIs...
# 5
Sorry for the late response but now my problem is solved. I have created a separate class which extends JInternalFrame and than called it from the MDI class. Now it seems very simple. Thanks kirillg and mbmerril for the help.
Solankya at 2007-7-12 20:18:47 > top of Java-index,Desktop,Core GUI APIs...