我使个初学者,对jbuilder和java还很陌生,请说得详细些,谢谢:)
程序代码如下:
public class Frame1 extends JFrame {
  private JPanel contentPane;
  private BorderLayout borderLayout1 = new BorderLayout();
  private JPanel jPanel1 = new JPanel();
  private XYLayout xYLayout1 = new XYLayout();
  private JTree jTree1 = new JTree();
  private JButton jButton1 = new JButton();
  private JPopupMenu jPopupMenu1 = new JPopupMenu();
  private JMenu jMenu1 = new JMenu();
  private JMenu jMenu2 = new JMenu();
  private JMenuItem jMenuItem1 = new JMenuItem();
  private JMenuItem jMenuItem2 = new JMenuItem();
  private JMenuItem jMenuItem3 = new JMenuItem();  //Construct the frame
  public Frame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  //Component initialization
  private void jbInit() throws Exception  {
    //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Frame Title");
    this.addKeyListener(new java.awt.event.KeyAdapter() {
  
    });
    //this.addjPopupMenu(jPopupMenu1);
    jPanel1.setLayout(xYLayout1);
    jButton1.setText("ok");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton1_actionPerformed(e);
      }
    });
    contentPane.setToolTipText("");
    jPanel1.setToolTipText("");
    jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
      //public void mouseClicked(MouseEvent e) {
        //jPanel1_mouseClicked(e);
      //}
    });
    jPopupMenu1.setInvoker(this);
    jPopupMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        jPopupMenu1_mouseClicked(e);
      }
    });
    jMenu1.setText("open");
    jMenuItem1.setText("hoio");
    jMenu2.setText("sfskl");
    jMenuItem2.setText("fenjierw");
    jMenuItem3.setText("sfbuiea");
    contentPane.add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jTree1,   new XYConstraints(20, 16, 309, 224));
    jPanel1.add(jButton1, new XYConstraints(196, 259, 81, 30));
    jPopupMenu1.add(jMenu1);
    jMenu1.add(jMenu2);
    jMenu1.add(jMenuItem1);
    jMenu2.add(jMenuItem2);
    jMenu2.add(jMenuItem3);
  }
  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }
class Tdata     /*二叉树的定义*/
          {
             int  data;
             Tdata  child,brother;
          }
    class  TreeLink  /*工作链表的定义*/
          {
             Tdata  Node;
             DefaultMutableTreeNode  a;   /*定义节点a*/
             TreeLink  next;   /*链指针*/
             TreeLink()
              {
                Node=null;
                next=null;
              }
        }
 /*程序框架*/
TreeLink  head,p;
Tdata data=new Tdata(),data1;
data.data=0;
int i;
for(i=1;i<10;i++){
  data1=new Tdata();
    data1.data=i;
    data1.child=data.child;
   data.child=data1;
  }
head=new TreeLink();    
DefaultMutableTreeNode root=new DefaultMutableTreeNode("root");
DefaultTreeModel mod;
p=new TreeLink();     
p.Node=data;
p.a=root;     
p.next=head.next;    
head.next=p;          
while(head.next!=null){
  p=head.next;     
  head.next=p.next;  
  Tdata  node=p.Node;
  node=node.child;
  while(node!=null){
    DefaultMutableTreeNode no=new DefaultMutableTreeNode(String.valueOf(node.data));
    
    p.a.add(no);
    TreeLink tt=new TreeLink();
    tt.Node=node;
    tt.a=no;
    tt.next=head.next;
    head.next=tt;
    node=node.brother;
  }
}
mod=new DefaultTreeModel(root);
jTree1.setModel(mod);
  }  void jPopupMenu1_mouseClicked(MouseEvent e) {
     if(e.getModifiers()==Event.META_MASK){
      jPopupMenu1.show(this,e.getX(),e.getY());
     }
  }  void jPanel1_mouseClicked(MouseEvent e) {
    jPopupMenu1.show(this,e.getX(),e.getY());
  }