jtree节点的单击事件 很简单 在线等 速度答的有加分

jtree节点的单击事件 很简单 在线等 速度答的有加分,第1张

import javax.swing.*

import javax.swing.tree.*

import java.awt.FlowLayout

import java.awt.GridLayout

public class TreeDemo extends JFrame{

JTree jTree=new JTree()

JTextField jTextField =new JTextField()

GridLayout lay=new GridLayout(1,1)

public TreeDemo(){

treeinit()

this.setSize(400,400)

this.setLayout(lay)

this.add(jTree)

this.add(jTextField)

this.setVisible(true)

jTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {

public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {

jTreeValueChanged(evt)

}

})

}

private void jTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {

DefaultMutableTreeNode selectedNode=(DefaultMutableTreeNode) jTree.getLastSelectedPathComponent()//返回最后选定的节点

if(selectedNode.toString().equals("child")){

jTextField.setText("I LOVE YOU")

}

}

public void treeinit(){

DefaultMutableTreeNode root=new DefaultMutableTreeNode("root")

DefaultMutableTreeNode father=new DefaultMutableTreeNode("father")

DefaultMutableTreeNode child=new DefaultMutableTreeNode("child")

father.add(child)

root.add(father)

TreeModel treeModel = new DefaultTreeModel(root)

jTree.setModel(treeModel)

}

public static void main(String args[]){

new TreeDemo()

}

}

import javax.swing.event.TreeSelectionEvent

import javax.swing.event.TreeSelectionListener

import javax.swing.tree.DefaultMutableTreeNode

import javax.swing.tree.TreePath

import javax.swing.JFrame

import java.awt.Color

public class StudentMain extends JFrame implements TreeSelectionListener,ActionListener {

private DefaultMutableTreeNode root

private DefaultMutableTreeNode nallbook

private DefaultMutableTreeNode nallbooksearch

private DefaultMutableTreeNode nusermes

private DefaultMutableTreeNode nusermessearch

private DefaultMutableTreeNode nowningfeeuser

private DefaultMutableTreeNode nowningfeeusersearch

private DefaultMutableTreeNode student_sea_tea_infor

private DefaultMutableTreeNode stu_sea_tea_infor

public StudentMain(int zhanghao){

super("欢迎使用重大成绩管理系统:")

root=new DefaultMutableTreeNode("系统")

nallbook=new DefaultMutableTreeNode("学生个人信息查询")

nusermes=new DefaultMutableTreeNode("学生个人成绩查询")

nowningfeeuser=new DefaultMutableTreeNode("学生成绩排名查询")

student_sea_tea_infor=new DefaultMutableTreeNode("查询所有任课老师信息")

root.add(nallbook)

root.add(nusermes)

root.add(nowningfeeuser)

root.add(student_sea_tea_infor)

nallbooksearch=new DefaultMutableTreeNode("学生个人信息查询")

nallbook.add(nallbooksearch)

nusermessearch=new DefaultMutableTreeNode("学生个人成绩查询")

nusermes.add(nusermessearch)

nowningfeeusersearch=new DefaultMutableTreeNode("学生成绩排名查询")

nowningfeeuser.add(nowningfeeusersearch)

stu_sea_tea_infor=new DefaultMutableTreeNode("查询所有任课老师信息")

student_sea_tea_infor.add(stu_sea_tea_infor)

tree=new JTree(root)

tree.setRowHeight(24)

tree.putClientProperty("JTree.LineStyle", "Angled")

tree.setRootVisible(true)

tree.addTreeSelectionListener(this)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/7998195.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-12
下一篇 2023-04-12

发表评论

登录后才能评论

评论列表(0条)

保存