高手指点:这样的错误怎么去除???谢谢!
package card;
import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;
class Jtree1 extends JTree{
}
public class eventFrame extends JFrame {
JSplitPane jSplitPane1 = new JSplitPane();
JTree jTree1 = new JTree();
public eventFrame() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setEnabled(true);
this.getContentPane().setLayout(null);
jSplitPane1.setBounds(new Rectangle(22, 13, 350, 278));
jSplitPane1.setDividerLocation(100);
this.getContentPane().add(jSplitPane1, null);
jSplitPane1.add(jTree1, JSplitPane.LEFT);
DefaultMutableTreeNode root = new DefaultMutableTreeNode("信用卡系统");
DefaultMutableTreeNode bitchThing = new DefaultMutableTreeNode("查询");
bitchThing = new DefaultMutableTreeNode("存款");
root.add(bitchThing);
bitchThing = new DefaultMutableTreeNode("取款");
root.add(bitchThing);
root.add(bitchThing);
jTree1 = new JTree(root);
jSplitPane1.add(jTree1,JSplitPane.LEFT);
jTree1.addTreeSelectionListener(this);
int mode = TreeSelectionModel.SINGLE_TREE_SELECTION;
jTree1.getSelectionModel().setSelectionMode(mode);
}
}
报的错是:
"eventFrame.java": addTreeSelectionListener(javax.swing.event.TreeSelectionListener) in javax.swing.JTree cannot be applied to () at line 48, column 12
怎么解决?谢谢!!!
------解决方案-------------------- jTree1.addTreeSelectionListener(this); 是在添加侦听器,里面的参数是TreeSelectionListener();
可以试试下面的:
jTree1.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
jTree1.getLastSelectedPathComponent();
//if nothing is selected
if (node == null)
return;
}
});
------解决方案--------------------尝试一下: jTree1.addTreeSelectionListener((TreeSelectionListener)this);//强制类型转换,