问题描述
未移动前移动后谁知道原因吗,附源码importjavax.swing.*;importjavax.swing.tree.*;importjavax.swing.event.*;importjava.awt.event.*;importjava.awt.*;importjava.io.*;importjava.util.*;importjavax.swing.table.DefaultTableModel;importjava.sql.*;publicclassTest3extendsJFrameimplementsTreeSelectionListener{privateJScrollPanejsp_tree,jsp_table;privateJTreetree;privateJTabletb;Connectionconn;ResultSetres;Statementsta;Objectname[]={"年份","学院","专业代码","专业","总分","英语","数学"};Objectinfo[][];Stringacademy,subject;intyear,code,total,en,math;publicTest3(){super("研究生录取信息查询系统");info=newObject[50][7];Containerc=getContentPane();//定义根节点DefaultMutableTreeNoderoot=newDefaultMutableTreeNode("区域选择");//定义树叶节点DefaultMutableTreeNodenode_e=newDefaultMutableTreeNode("华东");DefaultMutableTreeNodenode_s=newDefaultMutableTreeNode("华南");DefaultMutableTreeNodenode_n=newDefaultMutableTreeNode("华北");DefaultMutableTreeNodenode_c=newDefaultMutableTreeNode("华中");root.add(node_e);root.add(node_s);root.add(node_n);root.add(node_c);DefaultMutableTreeNodeleafnode1=newDefaultMutableTreeNode("上海交通大学");node_e.add(leafnode1);DefaultMutableTreeNodeleafnode2=newDefaultMutableTreeNode("厦门大学");node_e.add(leafnode2);DefaultMutableTreeNodeleafnode3=newDefaultMutableTreeNode("复旦大学");node_e.add(leafnode3);DefaultMutableTreeNodeleafnode4=newDefaultMutableTreeNode("中山大学");node_s.add(leafnode4);DefaultMutableTreeNodeleafnode5=newDefaultMutableTreeNode("深圳大学");node_s.add(leafnode5);DefaultMutableTreeNodeleafnode6=newDefaultMutableTreeNode("广西大学");node_s.add(leafnode6);DefaultMutableTreeNodeleafnode7=newDefaultMutableTreeNode("东北大学");node_n.add(leafnode7);DefaultMutableTreeNodeleafnode8=newDefaultMutableTreeNode("东北财经大学");node_n.add(leafnode8);DefaultMutableTreeNodeleafnode9=newDefaultMutableTreeNode("哈尔滨工业大学");node_n.add(leafnode9);DefaultMutableTreeNodeleafnode_10=newDefaultMutableTreeNode("武汉大学");node_c.add(leafnode_10);DefaultMutableTreeNodeleafnode_11=newDefaultMutableTreeNode("华中科技大学");node_c.add(leafnode_11);DefaultMutableTreeNodeleafnode_12=newDefaultMutableTreeNode("中南财经政法大学");node_c.add(leafnode_12);tree=newJTree(root);tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);//只能选一个结点tb=newJTable(info,name);jsp_tree=newJScrollPane(tree);jsp_table=newJScrollPane(tb);JSplitPanesplitPane=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,jsp_tree,jsp_table);tree.addTreeSelectionListener(this);//监听器c.add(splitPane);pack();setSize(800,600);setVisible(true);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});}publicvoidvalueChanged(TreeSelectionEvente){if(e.getSource()==tree){DefaultMutableTreeNodeselectionNode=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent();if(selectionNode.isLeaf()){StringnodeName=selectionNode.toString();if(nodeName.equals("中南财经政法大学")){zncj();}}}}privatevoidzncj(){inti=0;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundExceptionce){System.out.println("SQLException:"+ce.getMessage());}try{conn=DriverManager.getConnection("jdbc:odbc:mydb","","");sta=conn.createStatement();res=sta.executeQuery("select*fromzncjzf");while(res.next()){year=res.getInt("年份");academy=res.getString(2);code=res.getInt("专业代码");subject=res.getString(4);total=res.getInt("总分");en=res.getInt("英语");math=res.getInt("数学");info[i][0]=String.valueOf(year);info[i][1]=academy;info[i][2]=String.valueOf(code);info[i][3]=subject;info[i][4]=String.valueOf(total);info[i][5]=String.valueOf(en);info[i][6]=String.valueOf(math);i++;}conn.close();}catch(SQLExceptionbe){System.out.println("SQLException:"+be.getMessage());}}publicstaticvoidmain(Stringargs[]){newTest3();}}
解决方案
解决方案二:
图片放不出来移动前移动后
解决方案三:
就是中间竖的那条移动一下,JTable才能显示数据库内容,怎么回事?