Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
import javax.swing.tree.*;
import javax.swing.*;
import java.awt.*;
class MyNode extends DefaultMutableTreeNode
{
private String location;
public MyNode (String location, String description, int value)
{
this.location = location;
add (new DescriptionNode (description));
add (new ValueNode (value));
}
public String toString () { return location; }
}
class DescriptionNode extends DefaultMutableTreeNode
{
private String description;
public DescriptionNode (String description)
{
this.description = description;
}
public String toString () { return description; }
}
class ValueNode extends DefaultMutableTreeNode
{
private int value;
public ValueNode (int value)
{
this.value = value;
}
public String toString () { return ""+value; }
}
public class SmallTree extends JFrame // implements ActionListener
{
private JTree jtree;
public SmallTree ()
{
super ("Treedemo");
JPanel mainpanel = new JPanel ();
mainpanel.setLayout (new BorderLayout ());
this.getContentPane ().add (mainpanel);
DefaultMutableTreeNode root = new DefaultMutableTreeNode ();
for (int i = 0; i < 8; ++i)
{
DefaultMutableTreeNode mtn = new MyNode (""+i, " desc. " + i, i);
root.add (mtn);
}
jtree = new JTree (root);
mainpanel.add (jtree, BorderLayout.CENTER);
setSize (400, 400);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible (true);
}
public static void main (String args[])
{
new SmallTree ();
}
}