Is there a way of doing this without using an inner class

hi, i have developed a tree applet but it takes ages to load on my machine. I was wondering if i could get rid of the inner class that is created when "valuechanged" is called (line 28). I am posting my whole code, i hope someone can help. Cheers Rups
[email protected]
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.TreeSelectionListener;
import javax.swing.event.TreeSelectionEvent;
import java.net.*;
import java.applet.AppletContext;
import java.util.Enumeration;
public class SimpleTree extends JApplet  {
JTree tree = new JTree();
  public void init() {
   new SimpleTree();
  public SimpleTree() {
  //  WindowUtilities.setNativeLookAndFeel();
    Container content = getContentPane();
    Object[] hierarchy =
      { "Some Useful Web Links ",
        new Object[] { "Microsft","http://www.microsfot.com"},
        new Object[]{"Yahoo", "http://www.yahoo.com"}
    DefaultMutableTreeNode root = processHierarchy(hierarchy);
    final JTree tree = new JTree(root);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addTreeSelectionListener(new TreeSelectionListener() {
    public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)
    tree.getLastSelectedPathComponent();
    String hoopla = tree.getLastSelectedPathComponent().toString();
    if (node == null) return;
    if (node.isLeaf()) {
       try {
           getAppletContext().showDocument(new URL("file://c:/webstuff/"+hoopla),
"viewer1");
         }catch(Exception f) {
            System.out.println("" + f);           
    content.add(new JScrollPane(tree), BorderLayout.CENTER);
    setVisible(true);
  public DefaultMutableTreeNode processHierarchy(Object[] hierarchy) {
    DefaultMutableTreeNode node =
      new DefaultMutableTreeNode(hierarchy[0]);
    DefaultMutableTreeNode child;
    for(int i=1; i<hierarchy.length; i++) {
      Object nodeSpecifier = hierarchy;
if (nodeSpecifier instanceof Object[]) // Ie node with children
child = processHierarchy((Object[])nodeSpecifier);
else
child = new DefaultMutableTreeNode(nodeSpecifier); // Ie Leaf
node.add(child);
return(node);
public static void main(String [] args) {
JFrame f = new JFrame("") ;
Container contentPane = f.getContentPane();
contentPane.setLayout(new FlowLayout());
SimpleTree ta = new SimpleTree() ;
ta.init() ;
f.addWindowListener(new ExitListener());
f.setSize(250,500);
contentPane.add(ta,BorderLayout.CENTER);
f.setVisible(true) ;

import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.TreeSelectionListener;
import javax.swing.event.TreeSelectionEvent;
import java.net.*;
import java.applet.AppletContext;
import java.util.Enumeration;
public class SimpleTree extends JApplet implements TreeSelectionListener  {
      JTree tree = new JTree();
      public void init() {
      new SimpleTree();
      public SimpleTree() {
//  WindowUtilities.setNativeLookAndFeel();
      Container content = getContentPane();
      Object[] hierarchy =
      { "Some Useful Web Links ",
        new Object[] { "Microsft","http://www.microsfot.com"},
        new Object[]{"Yahoo", "http://www.yahoo.com"}
      DefaultMutableTreeNode root = processHierarchy(hierarchy);
      final JTree tree = new JTree(root);
      tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
      tree.addTreeSelectionListener( this );
        tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)
        tree.getLastSelectedPathComponent();
        String hoopla = tree.getLastSelectedPathComponent().toString();
        if (node == null) return;
        if (node.isLeaf()) {
        try {
        getAppletContext().showDocument(new URL("file://c:/webstuff/"+hoopla),
        "viewer1");
        }catch(Exception f) {
        System.out.println("" + f);           
      content.add(new JScrollPane(tree), BorderLayout.CENTER);
      setVisible(true);
      public void valueChanged(TreeSelectionEvent e) {
      DefaultMutableTreeNode node = (DefaultMutableTreeNode)
         tree.getLastSelectedPathComponent();
      String hoopla = tree.getLastSelectedPathComponent().toString();
      if (node == null) return;
      if (node.isLeaf()) {
         try {
            getAppletContext().showDocument(new URL("file://c:/webstuff/"+hoopla),
                                "viewer1");
         }catch(Exception f) {
            System.out.println("" + f);           
      public DefaultMutableTreeNode processHierarchy(Object[] hierarchy) {
      DefaultMutableTreeNode node =
         new DefaultMutableTreeNode(hierarchy[0]);
      DefaultMutableTreeNode child;
      for(int i=1; i<hierarchy.length; i++) {
         Object nodeSpecifier = hierarchy[ i ];
         if (nodeSpecifier instanceof Object[])  // Ie node with children
            child = processHierarchy((Object[])nodeSpecifier);
         else
            child = new DefaultMutableTreeNode(nodeSpecifier); // Ie Leaf
         node.add(child);
      return(node);
      public static void main(String [] args) {
      JFrame f = new JFrame("") ;
      Container contentPane = f.getContentPane();
      contentPane.setLayout(new FlowLayout());
      SimpleTree ta = new SimpleTree() ;
      ta.init() ;
//      f.addWindowListener(new ExitListener());
      f.setSize(250,500);
      contentPane.add(ta,BorderLayout.CENTER);
      f.setVisible(true) ;
}

Similar Messages

Maybe you are looking for

  • IPod no longer appears in Computer

    I use my ipod touch as a portable external hard drive, but after i downloaded the 3.1.3 update, it no longer appears in Computer. Anyone know what is going on??

  • Can wireless backup be on different network to internet connection?

    Can you backup to a wireless backup (say a Time Capsule) but connect to a different wireless access point for the internet?

  • Installing 1.5 and 1.6 at the same time

    I am an Oracle instructor and I need to teach the current version which is still on 1.5 but also I want to install 1.6 to review the new functionality. Can I do this in the same database? i.e. on my laptop. What issues do I need to be aware of? regar

  • Adobe Premiere Elements/AVCHD?

    Can anyone confirm if Adobe Premiere Elements 12 will import AVCHD at 50p? I have a Canon Legria HF R46 which I can't import into imovies from so wondered if Adobe Premiere Elements 12 would be the way to go? any help very much appreciated, thanks. A

  • Curve 9300, no data plan, gmail on wifi only

    Hello, I plan to buy a BB Curve 9300 but before I want to be 100% sure that I can configure it to be auto warned if I get a mail on my gmail account but only via wifi because I have no data plan. Thank you for your help; Regards :-)