| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 401 人关注过本帖
标题:树组 输出问题 ,求大侠帮助啊
取消只看楼主 加入收藏
一个人的孤独
Rank: 2
等 级:论坛游民
帖 子:45
专家分:56
注 册:2012-10-15
结帖率:87.5%
收藏
已结贴  问题点数:20 回复次数:3 
树组 输出问题 ,求大侠帮助啊
。。。。数组 名字和得分输不出来,不知道哪里错了 ,请求指点
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);
            }
        }
    }
}
搜索更多相关主题的帖子: double abstract public return 
2012-11-24 14:17
一个人的孤独
Rank: 2
等 级:论坛游民
帖 子:45
专家分:56
注 册:2012-10-15
收藏
得分:0 
谢谢你 ,终与可以执行了,我头都想爆了了 呵呵
2012-11-26 22:42
一个人的孤独
Rank: 2
等 级:论坛游民
帖 子:45
专家分:56
注 册:2012-10-15
收藏
得分:0 
谢谢你!要不是你我不知道还有多久才能弄出来
我还有些不明白 :你再帮我看一下好不?  在下感激不进
刚开始老报这个错误:
E:JAVAtry>javac TreeWin.java
TreeWin.java:19: TreeWin 不是抽象的,并且未覆盖 javax.swing.event.TreeSelectionL
istener 中的抽象方法 valueChanged(javax.swing.event.TreeSelectionEvent)
public class TreeWin extends JFrame implements TreeSelectionListener{
后来无赖我就在class TreeWin 前加了个抽象类关键字。

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

class Student{
    String name;
    double score;
    Student(String name,double score){
    this.name=name;
    this.score=score;
    }
    public String toString(){
    return name;
    }   
}

public class TreeWin extends JFrame implements TreeSelectionListener{
    JTree tree=null;
    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);
            }
        }
   

    public static void main(String args[]){
        new TreeWin();
        }
}
2012-11-26 22:59
一个人的孤独
Rank: 2
等 级:论坛游民
帖 子:45
专家分:56
注 册:2012-10-15
收藏
得分:0 
好像明白一些了
谢谢你了!
2012-11-27 21:46
快速回复:树组 输出问题 ,求大侠帮助啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017706 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved