// This example is from _Java Examples in a Nutshell_. (http://www.oreilly.com)
// Copyright (c) 1997 by David Flanagan
// This example is provided WITHOUT ANY WARRANTY either expressed or implied.
// You may study, use, modify, and distribute it for non-commercial purposes.
// For any commercial use, see http://www.davidflanagan.com/javaexamples

import com.sun.java.swing.*;       // Beta package name; will change
import java.awt.*;
import java.awt.event.*;

/**
 * Our SwingDemo program is a subclass of JPanel, a general-purpose
 * lightweight container that supports double-buffering.
 **/
public class SwingDemo extends JPanel {
  /**
   * The main program creates a window to put the panel in.
   **/
  public static void main(String[] args) {
    //JFrame extends frame, and adds a little bit of new Swing functionality
    JFrame frame = new JFrame("Swing Demo");

    // Arrange to detect when the user closes the window
    // This is exactly what we'd do in an ordinary AWT program.
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) { System.exit(0); }
    });
    
    // Specify what look & feel we want for our application.  Uncomment
    // the commented line to try a different look and feel.
    try {
      // UIManager.setUIFactory("com.sun.java.swing.basic.BasicFactory",frame);
      UIManager.setUIFactory("com.sun.java.swing.rose.RoseFactory",frame);
    } catch (ClassNotFoundException e) {}

    // Create the demonstration panel
    SwingDemo demo = new SwingDemo();

    // Specify a layout manager for the window, and add the panel to it.
    frame.setLayout(new BorderLayout());
    frame.add(demo, "Center");
    
    // Finally, set the initial size of the window, and make it appear
    frame.setSize(400, 350);
    frame.show();
  }

  /**
   * This constructor method creates the contents of the demonstration panel
   **/
  public SwingDemo() {
    // A tabbed pane displays many different sub-panes, each with its own
    // file folder-style "tab"
    JTabbedPane tabs = new JTabbedPane();

    // We add a bunch of sub-panes to the tabbed pane
    tabs.addTab("Choices", null, new ChoicePanel());
    tabs.addTab("Borders", null, new BorderPanel());
    tabs.addTab("Tree", null, new TreePanel(System.getProperty("java.home")));
    tabs.addTab("Table", null, new TablePanel());
    tabs.addTab("Internal Windows", null, new InternalFramePanel());

    // Specify which pane is displayed first
    tabs.setSelectedIndex(0);

    // And set a layout manager for this pane, adding the tabbed pane to it.
    this.setLayout(new BorderLayout());
    this.add(tabs, "Center");
  }
}
