|
How to implement internal frames
[ Back to article ] [ Sample overview ]
// // You'll need a frame which keeps all internal frames // - it could be an applet too.
public class MainFrame extends JFrame { protected JDesktopPane desk; protected DesktopManager deskman;
// constructor of the application public MainFrame() { // some initializations here... desk=new JDesktopPane(); getContentPane().add(desk,BorderLayout.CENTER); deskman = desk.getDesktopManager();
// add all internal frames, you need at startup desk.add(new RequestingFrame()); //... } // adds an internal frame to desktop public void addInternalFrame(JInternalFrame frame) { deskman.activateFrame(frame); } public static void main(String args[]) { new MainFrame(); } }
// // Now you have to implement the several internal frames //
public class RequestingFrame extends JInternalFrame { public RequestingFrame() { // call the father, see API for several constructor-paramaters super("My title",true,true,true,true);
// just add one button to the frame getContentPane().add(new JButton("Hello"),BorderLayout.CENTER); // that's it. } } |