日期:2014-05-20  浏览次数:20837 次

java的tree问题
请问一下大家 
UIManager.put()里面接的有什么参数啊!这个方法主要是做什么用的? 
Hashtable table = new Hashtable(); 
table.put()里面又是接的什么,有什么做用, 

还有就是addWindowListener(new BasicWindowMonitor())是个什么事件! 

import java.awt.*; 
import java.util.*; 
import java.awt.event.*; 
import javax.swing.*; 
import javax.swing.plaf.*; 
import javax.swing.tree.*; 

public class TestTree3 extends JFrame { 

JTree tree; 
DefaultTreeModel treeModel; 

public TestTree3() { 
super("Tree Test Example"); 
setSize(200, 150); 
addWindowListener(new BasicWindowMonitor()); 

// Add in our own customized tree icons 
UIManager.put("Tree.leafIcon", new ImageIcon("world.gif")); 
UIManager.put("Tree.openIcon", new ImageIcon("door.open.gif")); 
UIManager.put("Tree.closedIcon", new ImageIcon("door.closed.gif")); 
UIManager.put("Tree.expandedIcon", new ImageIcon("unlocked.gif")); 
UIManager.put("Tree.collapsedIcon", new ImageIcon("locked.gif")); 


public void init() { 
// Build the hierarchy of containers & objects 
String[] schoolyard = {"School", "Playground", "Parking Lot", "Field"}; 
String[] mainstreet = {"Grocery", "Shoe Shop", "Five & Dime", 
"Post Office"}; 
String[] highway = {"Gas Station", "Convenience Store"}; 
String[] housing = {"Victorian_blue", "Faux Colonial", 
"Victorian_white"}; 
String[] housing2 = {"Mission", "Ranch", "Condo"}; 
Hashtable homeHash = new Hashtable(); 
homeHash.put("Residential 1", housing); 
homeHash.put("Residential 2", housing2); 

Hashtable cityHash = new Hashtable(); 
cityHash.put("School grounds", schoolyard); 
cityHash.put("Downtown", mainstreet); 
cityHash.put("Highway", highway); 
cityHash.put("Housing", homeHash); 

Hashtable worldHash = new Hashtable(); 
worldHash.put("My First VRML World", cityHash); 

// Build our tree out of our big hashtable 
tree = new JTree(worldHash); 

// Pick an angled line style 
tree.putClientProperty("JTree.lineStyle", "Angled"); 
getContentPane().add(tree, BorderLayout.CENTER); 


public static void main(String args[]) { 
TestTree3 tt = new TestTree3(); 
tt.init(); 
tt.setVisible(true); 



这一段代码报错,说找不到符号 
符号:类 BasicWindowMonitor 
位置:类TestTree3 
addWindowListener(new BasicWindowMonitor()); 
^

------解决方案--------------------
将addWindowListener(new BasicWindowMonitor()); 
改成:addWindowListener(new WindowAdapter(){});

可能是自定义的类。