import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class InternalFrameSample extends JFrame implements ActionListener{

  JDesktopPane desktop;
  JButton b1, b2, b3, b4, b5, b6, b7,b8;
  int offsetx=50; int offsety=50;
  public InternalFrameSample() {
	super("Internal Frame Demo");	

	desktop = new JDesktopPane();

	JToolBar toolbar = new JToolBar();
	b1 = new JButton ("Scroll");
	b2 = new JButton ("Split");
	b3 = new JButton ("Tree");
	b4 = new JButton ("Table");
	b5 = new JButton ("Tabs");
	b6 = new JButton ("Motif LF");
        b7 = new JButton ("Metal LF");
	b8 = new JButton ("Windows LF");

        toolbar.add(b1);  b1.addActionListener(this);
        toolbar.add(b2);  b2.addActionListener(this);
        toolbar.add(b3);  b3.addActionListener(this);
	toolbar.add(b4);  b4.addActionListener(this);
        toolbar.add(b5);  b5.addActionListener(this);
        toolbar.add(b6);  b6.addActionListener(this);
        toolbar.add(b7);  b7.addActionListener(this);
	toolbar.add(b8);  b8.addActionListener(this);

        //Add the desktop pane to this panel.
	desktop.setLayout(new BorderLayout());
	desktop.add("North", toolbar);
	setContentPane(desktop);
   }

   public void actionPerformed (ActionEvent e) {
	JInternalFrame frame;
	if (e.getSource() == b1) {
	    createInternalFrame("Scroll", new ScrollSample());
        } else if (e.getSource() == b2) {
	    createInternalFrame("Split", new SplitSample());
        } else if (e.getSource() == b3) {
	    createInternalFrame("Tree", new TreeSample());
        } else if (e.getSource() == b4) {
	    createInternalFrame("Table", new TableSample());
	} else if (e.getSource() == b5) {
	    createInternalFrame("Tab", new TabbedSample());
        } else if (e.getSource() == b6) {
	    changeLF(1);
        } else if (e.getSource() == b7) {
            changeLF(2);
        } else if (e.getSource() == b8) {
	    changeLF(3);
        }
   }

   public void changeLF(int what) {
        String lf ="";
          if (what==1) { lf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";}
     else if (what==2) { lf = "javax.swing.plaf.metal.MetalLookAndFeel";}
     else if (what==3) { lf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";}
     try {
	UIManager.setLookAndFeel(lf);
     	SwingUtilities.updateComponentTreeUI(this);
     } catch(Exception e) { e.printStackTrace(); }
  } 

	

   public void createInternalFrame(String title, Container what) {
           JInternalFrame fr = new JInternalFrame(title, true, true, true, true);
           fr.setContentPane(what);
           fr.setSize(300,300);
           fr.setLocation(offsetx,offsety);
	   offsetx = offsetx+20;
	   offsety = offsety+20;
	   
           desktop.add(fr);
           try {
            fr.setSelected(true);
           } catch (java.beans.PropertyVetoException e2) {}
          fr.setVisible(true);
   }

	   
   public static void main (String args[]) {
	InternalFrameSample frame = new InternalFrameSample();
	frame.pack();
	frame.show();
   }
}


         
