我需要树形菜单的java方面的学习材料,视频,笔记都行,谁有给我发个链接,或者邮箱都行,谢谢

树形结构图,树形菜单,最好有简单的教程,或者视频,容易学的发到我邮箱miciing@sohu.com。谢谢了。... 树形结构图, 树形菜单,最好有简单的教程,或者视频,容易学的发到我邮箱miciing@sohu.com。谢谢了。 展开
 我来答
385lphuir
2011-06-30 · TA获得超过1247个赞
知道大有可为答主
回答量:3592
采纳率:90%
帮助的人:794万
展开全部
package com.csii;

import java.awt.GridLayout;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeSelectionModel;

public class TreeDemo1 extends JFrame implements TreeSelectionListener {

private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTree jTree = null;
private JEditorPane jEditorPane = null;
private JScrollPane jScrollPane = null;

public JScrollPane getjScrollPane() {
if(jScrollPane==null){
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJTree());
}
return jScrollPane;
}

DefaultMutableTreeNode top = null; // @jve:decl-index=0:

/**
* This is the default constructor
*/
public TreeDemo1() {
super();
initialize();
}

/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(438, 309);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}

/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(1);
gridLayout.setColumns(2);
jContentPane = new JPanel();
jContentPane.setLayout(gridLayout);
jContentPane.add(getjScrollPane(), null);
jContentPane.add(getJEditorPane(), null);
}
return jContentPane;
}

/**
* This method initializes jTree
*
* @return javax.swing.JTree
*/
private JTree getJTree() {
if (jTree == null) {
top = new DefaultMutableTreeNode("黄山");
createNodes(top);
jTree = new JTree(top);
jTree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
jTree.addTreeSelectionListener(this);

}
return jTree;
}

private void createNodes(DefaultMutableTreeNode top) {
DefaultMutableTreeNode jingdian = null, jiaotong = null, zhusu = null, binguan = null, luying = null, jiesu = null;
jingdian = new DefaultMutableTreeNode("景点");
jingdian.add(new DefaultMutableTreeNode("景点1"));
jingdian.add(new DefaultMutableTreeNode("景点2"));
jiaotong = new DefaultMutableTreeNode("交通");
jiaotong.add(new DefaultMutableTreeNode("路线1"));
jiaotong.add(new DefaultMutableTreeNode("路线2"));
jiaotong.add(new DefaultMutableTreeNode("路线3"));
zhusu = new DefaultMutableTreeNode("住宿");
zhusu.add(new DefaultMutableTreeNode("A住宿"));
zhusu.add(new DefaultMutableTreeNode("B住宿"));
zhusu.add(new DefaultMutableTreeNode("C住宿"));

binguan = new DefaultMutableTreeNode("宾馆");
binguan.add(new DefaultMutableTreeNode("X宾馆"));
binguan.add(new DefaultMutableTreeNode("Y宾馆"));
binguan.add(new DefaultMutableTreeNode("Z宾馆"));
binguan.add(new DefaultMutableTreeNode("XYZ宾馆"));
luying = new DefaultMutableTreeNode("露营");
luying.add(new DefaultMutableTreeNode("方式1"));
luying.add(new DefaultMutableTreeNode("方式2"));
jiesu = new DefaultMutableTreeNode("借宿");
jiesu.add(new DefaultMutableTreeNode("借宿1"));
jiesu.add(new DefaultMutableTreeNode("借宿2"));
jiesu.add(new DefaultMutableTreeNode("借宿3"));
top.add(jingdian);
top.add(jiaotong);
top.add(zhusu);
top.add(binguan);
top.add(luying);
top.add(jiesu);
}

/**
* This method initializes jEditorPane
*
* @return javax.swing.JEditorPane
*/
private JEditorPane getJEditorPane() {
if (jEditorPane == null) {
jEditorPane = new JEditorPane();
}
return jEditorPane;
}

@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree
.getLastSelectedPathComponent();

if (node == null)
// Nothing is selected.
return;
if(node.isRoot()){
jEditorPane.setText("黄山的简介");
}
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {

try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){
e.printStackTrace();
}
new TreeDemo1().setVisible(true);
}
});
}

}

追问
谢谢。有没有能在jsp中实现的?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
chenhui_de
2011-06-30
知道答主
回答量:6
采纳率:0%
帮助的人:0
展开全部
在网上搜索“智能博客” 的视频吧,这个视频 还是差不多的,推荐你看看呵呵
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式