树组 输出问题 ,求大侠帮助啊
。。。。数组 名字和得分输不出来,不知道哪里错了 ,请求指点import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import javax.swing.event.*;
public class Tree {
public static void main(String args[]){
new TreeWin();
}
}
class Student{
String name;
double score;
//doube MajorSpeciaty;
Student(String name,double score){
this.name=name;
this.score=score;
}
public String toString(){
return name;
}
abstract class TreeWin extends JFrame implements TreeSelectionListener{
JTree tree;
JTextArea showText;
TreeWin(){
DefaultMutableTreeNode root=new DefaultMutableTreeNode("华北科技学院");
DefaultMutableTreeNode node=new DefaultMutableTreeNode("信息与计算科学");
DefaultMutableTreeNode nodeson1=new DefaultMutableTreeNode(new Student("三",98));
DefaultMutableTreeNode nodeson2=new DefaultMutableTreeNode(new Student("四",88));
DefaultMutableTreeNode nodeson3=new DefaultMutableTreeNode(new Student("五",78));
root.add(node);
node.add(nodeson1);
node.add(nodeson2);
node.add(nodeson3);
tree=new JTree(root);
tree.addTreeSelectionListener(this);
showText=new JTextArea();
setLayout(new GridLayout(1,2));
add(new JScrollPane(tree));
add(new JScrollPane(showText));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setBounds(350,400,300,300);
validate();
}
public void valueChaged(TreeSelectionEvent e){
DefaultMutableTreeNode node=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
if(node.isLeaf()){
Student s=(Student)node.getUserObject();
showText.append(s.name+","+s.score+"."+"\n");
}
else {
showText.setText(null);
}
}
}
}