⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 collegeinfopanel.java

📁 使用JBuilder基于Oracle数据库的课程作业
💻 JAVA
字号:
package StudentManageSystem.factionpanels.infopanel;

import com.borland.jbcl.layout.XYConstraints;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import StudentManageSystem.link.SQLRunner;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import java.sql.SQLException;
import javax.swing.JTextArea;

public class CollegeInfoPanel extends InfoPanel {
    public CollegeInfoPanel(boolean e){
        try {
            initialize(e);//初始化父类
        } catch (Exception ex) {
        }
    }

    protected void initialize(boolean e){
        try {
            super.initialize(e);

        } catch (Exception ex) {
        }
        jLabel1.setText("学院名");
        jTextField_coname.setText("jTextField1");
        jLabel2.setText("学院编号");
        jTextField_college_no.setText("jTextField2");
        jLabel4.setText("联系电话");
        jTextField_phone.setText("jTextField3");
        jLabel6.setText("院长");
        jLabel3.setText("简介");
        jTextArea_introduction.setText("jTextArea1");
        this.add(jLabel1, new XYConstraints(56, 45, 82, 38));
        this.add(jTextField_coname, new XYConstraints(128, 53, 95, 29));
        this.add(jLabel2, new XYConstraints(297, 51, 80, 31));
        this.add(jTextField_college_no, new XYConstraints(427, 52, 96, 30));
        this.add(jLabel6, new XYConstraints(56, 112, 71, 37));
        this.add(jComboBox_tname, new XYConstraints(128, 113, 163, 32));
        this.add(jLabel4, new XYConstraints(54, 169, 67, 33));
        this.add(jTextField_phone, new XYConstraints(128, 167, 180, 32));
        this.add(jLabel3, new XYConstraints(54, 213, 58, 31));
        this.add(jTextArea_introduction, new XYConstraints(126, 221, 396, 108));
    }

    public void setSwingEnable(boolean e) {
        jTextField_coname.setEnabled(e);
        jTextField_college_no.setEnabled(e);
        jTextField_phone.setEnabled(e);
        jComboBox_tname.setEnabled(e);
        jTextArea_introduction.setEditable(e);
    }

    public boolean delete() {
        return SQLRunner.executSql("delete from college where college_no='"+keyValue+"'");
    }

    public boolean update() {
        try{
            String teacher_no;
             if(jComboBox_tname.getSelectedItem()==null){
                 JOptionPane.showMessageDialog(null,"学院不能为空","系统提示",JOptionPane.ERROR_MESSAGE);
                 return false;
             }else{
                 String tname=(String)(jComboBox_tname.getSelectedItem());
                 ResultSet rs=SQLRunner.getResult("select * from teacher where tname='"+tname+"'");
                 if(!rs.next())return false;//System.out.println("can't find clname");
                 teacher_no=rs.getString("teacher_no").trim();//不该不抱错
             }
             String coname= jTextField_coname.getText().trim();
             String college_no=jTextField_college_no.getText().trim();
             String phone=jTextField_phone.getText().trim();
             String introduction=jTextArea_introduction.getText().trim();
             String updatesql="update college set PRESIDENT='"+teacher_no+"',phone='"+phone+"',coname='"+coname+"',INTRODUCTON='"+introduction+"' where college_no='"+college_no+"'";
             return SQLRunner.executSql(updatesql);
         }catch(Exception e){
             JOptionPane.showMessageDialog(null,e.toString(),"系统提示",JOptionPane.ERROR_MESSAGE);
             return false;
         }


    }

    public void setAllInfo(String keyValue) {
        updateModel=true;//
         this.keyValue=keyValue;//
         jButton_remove.setVisible(enable);
         jTextField_college_no.setEditable(false);
         try {
             //rs.next();
             ResultSet rs=SQLRunner.getResult("select * from college where college_no='"+keyValue+"'");
             if(!rs.next())return;

             addItem(jComboBox_tname,"select tname from teacher,college where teacher.college_no='"+keyValue+"' group by tname","tname");
             String tname;
             ResultSet rpt=SQLRunner.getResult("select * from teacher,college where teacher.teacher_no=college.PRESIDENT and college.college_no='"+keyValue+"'");
             if(rpt.next()){
                 jComboBox_tname.setSelectedItem(rpt.getString("tname"));
             }else{
                 jComboBox_tname.setSelectedItem(null);
             }

             jComboBox_tname.setSelectedItem("");
             jTextField_phone.setText(rs.getString("phone"));
             jTextField_college_no.setText(rs.getString("college_no"));
             jTextField_coname.setText(rs.getString("coname").trim());
             jTextArea_introduction.setText(rs.getString("INTRODUCTON"));
         } catch (SQLException ex) {
             System.out.print(ex.toString());
         }

    }


    public void setAllNew() {

        jButton_remove.setVisible(false);
        jTextField_college_no.setEditable(true);
        jTextField_coname.setText("");
        jTextField_college_no.setText("");
        jTextField_phone.setText("");
        jComboBox_tname.removeAllItems();
        jTextArea_introduction.setText("");
    }

    JLabel jLabel1 = new JLabel();
    JTextField jTextField_coname = new JTextField();
    JLabel jLabel2 = new JLabel();
    JTextField jTextField_college_no = new JTextField();
    JLabel jLabel4 = new JLabel();
    JTextField jTextField_phone = new JTextField();
    JLabel jLabel6 = new JLabel();
    JComboBox jComboBox_tname = new JComboBox();
    JLabel jLabel3 = new JLabel();
    JTextArea jTextArea_introduction = new JTextArea();
    public boolean insert() {
        try{
            String teacher_no;
             if(jComboBox_tname.getSelectedItem()==null){
                 teacher_no="";
             }else{
                 String tname=(String)(jComboBox_tname.getSelectedItem());
                 ResultSet rs=SQLRunner.getResult("select * from teacher where tname='"+tname+"'");
                 if(!rs.next())return false;//System.out.println("can't find clname");
                 teacher_no=rs.getString("teacher_no").trim();//不该不抱错
             }
             String coname= jTextField_coname.getText().trim();
             String college_no=jTextField_college_no.getText().trim();
             String phone=jTextField_phone.getText().trim();
             String introduction=jTextArea_introduction.getText().trim();
             String insertsql="insert into college(college_no,coname,PRESIDENT,phone,INTRODUCTON) values('"+college_no+"','"+coname+"','"+teacher_no+"','"+phone+"','"+introduction+"')";

             return SQLRunner.executSql(insertsql);
         }catch(Exception e){
             JOptionPane.showMessageDialog(null,e.toString(),"系统提示",JOptionPane.ERROR_MESSAGE);
             return false;
         }

    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -