/* This file is part of the algoviz@vt collection of algorithm visualizations. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this distribution. If not, see . */ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ import avl.*; import splayTree.*; import bst.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; /** * * @author Akash Jana */ import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class Main extends JApplet { bst.TreeApplet panel1; static avl.TreeApplet panel2; splayTree.TreeApplet panel3; static JTabbedPane tabbedPane; static Main main; public Main() { tabbedPane = new JTabbedPane(); ImageIcon icon = createImageIcon(""); panel1 = new bst.TreeApplet(); tabbedPane.addTab("BST", icon, panel1, ""); tabbedPane.setMnemonicAt(0, KeyEvent.VK_1); panel2 = new avl.TreeApplet(); tabbedPane.addTab("AVL", icon, panel2, ""); tabbedPane.setMnemonicAt(1, KeyEvent.VK_2); panel3 = new splayTree.TreeApplet(); tabbedPane.addTab("Splay Tree", icon, panel3, ""); tabbedPane.setMnemonicAt(2, KeyEvent.VK_3); //Add the tabbed pane to this panel. add(tabbedPane); tabbedPane.addChangeListener(new tabChangeListener()); //The following line enables to use scrolling tabs. tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); } public class tabChangeListener implements ChangeListener{ public void stateChanged(ChangeEvent e) { int index=((JTabbedPane)e.getSource()).getSelectedIndex(); } } protected JComponent makeTextPanel(String text) { JPanel panel = new JPanel(false); JLabel filler = new JLabel(text); filler.setHorizontalAlignment(JLabel.CENTER); panel.setLayout(new GridLayout(1, 1)); panel.add(filler); return panel; } /** Returns an ImageIcon, or null if the path was invalid. */ protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = Main.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } } /** * Create the GUI and show it. For thread safety, * this method should be invoked from * the event dispatch thread. */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame(""); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); main=new Main(); //Add content to the window. frame.add(main, BorderLayout.CENTER); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event dispatch thread: //creating and showing this application's GUI. SwingUtilities.invokeLater(new Runnable() { public void run() { //Turn off metal's use of bold fonts UIManager.put("swing.boldMetal", Boolean.FALSE); createAndShowGUI(); } }); } }