?? mysearchpanel.java~41~
字號:
package superframe.factionpanels.searchpanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import com.borland.jbcl.layout.XYConstraints;
import com.borland.jbcl.layout.XYLayout;
import superframe.factionpanels.ButtonTablePanel;
import superframe.factionpanels.WelcomePanel;
import superframe.factionpanels.infopanel.MyStudentInfoPanel;
import superframe.factionpanels.infopanel.MyStudentInfoPanel;
import superframe.link.SQLRunner;
import superframe.factionpanels.TablePanel;
import com.borland.jbcl.layout.*;
public class MySearchPanel extends JPanel implements ActionListener{
boolean enable;
String college_no;
DefaultMutableTreeNode top;
XYLayout xYLayout1 = new XYLayout();
JScrollPane jScrollPanel_tree = new JScrollPane();
JTree jTree_stu=new JTree(top);
JPanel jPanel_refTree = new JPanel();
JButton jButton_refTree = new JButton();
MyStudentInfoPanel studentInfoPanel;
//ButtonTablePanel buttonTablePanel;
TablePanel tablePanel=new TablePanel();
WelcomePanel welcomePanel=new WelcomePanel();
JButton jButton_new = new JButton();
XYLayout xYLayout2 = new XYLayout();
public MySearchPanel(String cno,boolean e) {
enable=e;
college_no=cno;
addNodes();
jTree_stu=new JTree(top);
studentInfoPanel=new MyStudentInfoPanel(e);
//buttonTablePanel=new ButtonTablePanel(enable);
try {
jbInit();
this.jButton_new.setVisible(e);
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(xYLayout1);
xYLayout1.setWidth(840);
xYLayout1.setHeight(470);
jButton_refTree.setText("刷新");
jButton_refTree.addActionListener(new
MySearchPanel_jButton_refTree_actionAdapter(this));
jTree_stu.addTreeSelectionListener(new
MySearchPanel_jTree_stu_treeSelectionAdapter(this));
jButton_new.setText("新建");
jButton_new.addActionListener(new
MySearchPanel_jButton_new_actionAdapter(this));
jPanel_refTree.setLayout(xYLayout2);
this.add(jScrollPanel_tree, new XYConstraints(0, 0, 170, 430));
jScrollPanel_tree.getViewport().add(jTree_stu);
this.add(jPanel_refTree, new XYConstraints(0, 430, 170, 40));
this.add(studentInfoPanel, new XYConstraints(170, 0, 670, 470));
//this.add(buttonTablePanel, new XYConstraints(170, 0, 670, 470));
this.add(tablePanel, new XYConstraints(170, 0, 670, 470));
this.add(welcomePanel, new XYConstraints(170, 0, 670, 470)); //this.buttonTablePanel.jButton_new.addActionListener(this);
jPanel_refTree.add(jButton_new, new XYConstraints(87, 7, 66, 26));
jPanel_refTree.add(jButton_refTree, new XYConstraints(13, 7, 60, 26));
this.showWelcomeView();
}
public void addNodes(){
try {
if(top!=null)top.removeAllChildren();
ResultSet rs=SQLRunner.getResult("select * from college where college_no='"+college_no+"'");
if(!rs.next())return;
top=new DefaultMutableTreeNode(college_no+rs.getString("coname"));
ResultSet rdp=SQLRunner.getResult("select * from department where department.college_no='"+college_no+"'");
while (rdp.next()) {
String dno=rdp.getString("DEPART_NO");
String dpname=rdp.getString("dpname");
DefaultMutableTreeNode dp=new DefaultMutableTreeNode(dno+'/'+dpname);
top.add(dp);
ResultSet rcl=SQLRunner.getResult("select * from class where class.depart_no='"+dno+"'");
while (rcl.next()) {
String clno=rcl.getString("class_no");
System.out.println(clno);
String clname=rcl.getString("clname");
DefaultMutableTreeNode cl=new DefaultMutableTreeNode(clno+'/'+clname);
dp.add(cl);
ResultSet rst=SQLRunner.getResult("select * from student where student.class_no='"+clno+"'");
while (rst.next()) {
String sno=rst.getString("Stu_no");
System.out.println(clno);
String sname=rst.getString("sname");
DefaultMutableTreeNode s=new DefaultMutableTreeNode(sno+'/'+sname);
cl.add(s);
}
}
}
} catch (SQLException ex) {
}
}
public void jTree_stu_valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)jTree_stu.getLastSelectedPathComponent();
setView(node.toString());
}
/**
* setView
*
* @param string String
*/
public void setView(String s) {
String sub=(s.trim());
sub=sub.substring(sub.length()-1,sub.length());
if(sub.trim().equals("院")){
String cno=s.substring(0,2);
showTableView("select dpname,count(Stu_no) from Studentinfo where college_no='"+cno+"' group by dpname");
}else if(sub.trim().equals("系")){
String dno=s.substring(0,2);
showTableView("select clname,count(Stu_no) from Studentinfo where depart_no='"+dno+"' group by clname");
}else if(sub.trim().equals("班")){
String clno=s.substring(0,4);
showTableView("select stu_no,sname,sex,nation,source,class_no from Student where class_no='"+clno+"'");
}else{
String sno=s.substring(0,8);
System.out.println(sno);
showLeavesView(sno);
}
}
/**
* showLeavesView
*
* @param sno String
*/
public void showLeavesView(String sno) {
tablePanel.setVisible(false);
welcomePanel.setVisible(false);
//buttonTablePanel.setVisible(false);
studentInfoPanel.setAllInfo(sno);
studentInfoPanel.setVisible(true);
}
/*public void showButtonTableView(String sql) {
tablePanel.setVisible(false);
welcomePanel.setVisible(false);
studentInfoPanel.setVisible(false);
//buttonTablePanel.resetTable(sql);
//buttonTablePanel.setVisible(true);
}*/
/**
* showTableView
*
* @param string String
*/
public void showTableView(String sql) {
studentInfoPanel.setVisible(false);
welcomePanel.setVisible(false);
//buttonTablePanel.setVisible(false);
tablePanel.resetTable(sql);
tablePanel.setVisible(true);
}
void showWelcomeView(){
studentInfoPanel.setVisible(false);
//buttonTablePanel.setVisible(false);
tablePanel.setVisible(false);
welcomePanel.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
showLeavesView();
DefaultMutableTreeNode node = (DefaultMutableTreeNode)jTree_stu.getLastSelectedPathComponent();
String s=node.toString().substring(0,4);
studentInfoPanel.insert();
}
/**
* showLeavesView
*/
public void showLeavesView() {
tablePanel.setVisible(false);
welcomePanel.setVisible(false);
//buttonTablePanel.setVisible(false);
//studentInfoPanel.resetKeyValue();
studentInfoPanel.setVisible(true);
}
public void jButton_new_actionPerformed(ActionEvent e) {
studentInfoPanel.setAllNew();
tablePanel.setVisible(false);
welcomePanel.setVisible(false);
//buttonTablePanel.setVisible(false);
//studentInfoPanel.resetKeyValue();
studentInfoPanel.setVisible(true);
}
public void jButton_refTree_actionPerformed(ActionEvent e) {
this.addNodes();
this.setVisible(false);
this.setVisible(true);
}
}
class MySearchPanel_jButton_refTree_actionAdapter implements ActionListener {
private MySearchPanel adaptee;
MySearchPanel_jButton_refTree_actionAdapter(MySearchPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton_refTree_actionPerformed(e);
}
}
class MySearchPanel_jButton_new_actionAdapter implements ActionListener {
private MySearchPanel adaptee;
MySearchPanel_jButton_new_actionAdapter(MySearchPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton_new_actionPerformed(e);
}
}
class MySearchPanel_jTree_stu_treeSelectionAdapter implements
TreeSelectionListener {
private MySearchPanel adaptee;
MySearchPanel_jTree_stu_treeSelectionAdapter(MySearchPanel adaptee) {
this.adaptee = adaptee;
}
public void valueChanged(TreeSelectionEvent e) {
adaptee.jTree_stu_valueChanged(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -