标题:java里的一个 树组控件 问题 想了很久都没想出来 求大侠帮助!
取消只看楼主
一个人的孤独
Rank: 2
等 级:论坛游民
帖 子:45
专家分:56
注 册:2012-10-15
结帖率:87.5%
 问题点数:0 回复次数:0 
java里的一个 树组控件 问题 想了很久都没想出来 求大侠帮助!
源程序:import javax.swing.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import java.awt.*;
import javax.swing.border.*;

import javax.swing.tree.*;
import javax.swing.event.*;
//import javax.swing.event.treeSelectionEvent;


public class StuManagement {
    public static  void main(String args[]){
        StuWindow win=new StuWindow("学生管理系统");
        
        new DynoliciousBox();
        
        new TreeWin();
        }   
    }
   
class StuWindow extends JFrame{
    JMenuBar menubar;
    JMenu menu;
    JMenuItem item1,item2;
    StuWindow(String s){
    setTitle(s);
    setSize(700 ,550);
    setLocation(300,100);
    setVisible(true);
    menubar=new JMenuBar();
    menu=new JMenu("文件");
    item1=new JMenuItem("打开",new ImageIcon("open.gif"));
    item2=new JMenuItem("保存",new ImageIcon("save.gif"));
    item1.setAccelerator(KeyStroke.getKeyStroke('o'));
    item2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
    menu.add(item1);
    menu.addSeparator();
    menu.add(item2);
    menubar.add(menu);
    setJMenuBar(menubar);
    validate();
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
}
   
class DynoliciousBox extends JFrame{
    Box baseBox,boxV1,boxV2;
    DynoliciousBox(){
    boxV1=Box.createVerticalBox();
    boxV1.add(new JLabel("输入你的姓名"));
    boxV1.add(Box.createVerticalStrut(8));
    boxV1.add(new JLabel("输入你的学号"));
    boxV1.add(Box.createVerticalStrut(8));
    boxV1.add(new JLabel("输入你的专业"));
    //boxV1.add(Box.createVerticalStrut(8));
    boxV2=Box.createVerticalBox();
    boxV2.add(new JTextField(16));
    boxV2.add(Box.createVerticalStrut(8));
    boxV2.add(new JTextField(16));
    boxV2.add(Box.createVerticalStrut(8));
    boxV2.add(new JTextField(16));
    baseBox=Box.createHorizontalBox();
    baseBox.add(boxV1);
    baseBox.add(Box.createHorizontalStrut(10));
    baseBox.add(boxV2);
    setLayout(new FlowLayout());
    add(baseBox);
    validate();
    setBounds(350,200,400,200);
    setVisible(true);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
}

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

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");
                }
            }
        }
        
E:\JAVA\try>javac StuManagement.java
StuManagement.java:90: TreeWin 不是抽象的,并且未覆盖 javax.swing.event.TreeSele
ctionListener 中的抽象方法 valueChanged(javax.swing.event.TreeSelectionEvent)
class TreeWin extends JFrame implements TreeSelectionListener{
^
1 错误
搞不懂 为什么说我没有覆盖javax.swing.event.TreeSelectionListener中的抽象方法 valueChanged(javax.swing.event.TreeSelectionEvent)

求帮助。。。。。。。。。。。。
搜索更多相关主题的帖子: 源程序 import public java 管理系统 
2012-11-24 01:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-388218-1-1.html




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

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