1个回答
展开全部
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.event.*;
import javax.swing.event.*;
public class JTree2 extends JFrame
{
JPanel cp=new JPanel();
JTree jtree;
DefaultMutableTreeNode root;
public JTree2()
{
this.setSize(300,300);
this.setTitle("try to use tree");
cp=(JPanel)this.getContentPane();
cp.setLayout(new BorderLayout());
root=new DefaultMutableTreeNode("school");
createTree(root);
jtree=new JTree(root);
cp.add(jtree,BorderLayout.CENTER);
}
public static void main(String[] args)
{
JTree2 JTree2 = new JTree2();
JTree2.setVisible(true);
}
private void createTree(DefaultMutableTreeNode root)
{
DefaultMutableTreeNode classroom=null;
DefaultMutableTreeNode number=null;
classroom=new DefaultMutableTreeNode("classroom");
root.add(classroom);
for(int i=1;i<=8;i++)
{
number=new DefaultMutableTreeNode("No."+String.valueOf(i));
if(i==4)
{
for(int j=1;j<=5;j++)
{
number.add(new DefaultMutableTreeNode("seat"+String.valueOf(j)));
}
}
classroom.add(number);
}
}
protected void processWindowEvent(WindowEvent e)
{
if(e.getID()==WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
}
自己用API去查这个类
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.event.*;
import javax.swing.event.*;
public class JTree2 extends JFrame
{
JPanel cp=new JPanel();
JTree jtree;
DefaultMutableTreeNode root;
public JTree2()
{
this.setSize(300,300);
this.setTitle("try to use tree");
cp=(JPanel)this.getContentPane();
cp.setLayout(new BorderLayout());
root=new DefaultMutableTreeNode("school");
createTree(root);
jtree=new JTree(root);
cp.add(jtree,BorderLayout.CENTER);
}
public static void main(String[] args)
{
JTree2 JTree2 = new JTree2();
JTree2.setVisible(true);
}
private void createTree(DefaultMutableTreeNode root)
{
DefaultMutableTreeNode classroom=null;
DefaultMutableTreeNode number=null;
classroom=new DefaultMutableTreeNode("classroom");
root.add(classroom);
for(int i=1;i<=8;i++)
{
number=new DefaultMutableTreeNode("No."+String.valueOf(i));
if(i==4)
{
for(int j=1;j<=5;j++)
{
number.add(new DefaultMutableTreeNode("seat"+String.valueOf(j)));
}
}
classroom.add(number);
}
}
protected void processWindowEvent(WindowEvent e)
{
if(e.getID()==WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
}
自己用API去查这个类
追问
如何在左边显示树状菜单,在右边显示几个textFeild和button
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询