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

📄 project_info.java~38~

📁 一款高校科研管理系统
💻 JAVA~38~
字号:
package scince;

import java.awt.*;

import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class project_Info extends JFrame {
    public project_Info() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        jLabel1.setText("项目编号*");
        jLabel1.setBounds(new Rectangle(26, 10, 89, 31));
        jTextField6.setBounds(new Rectangle(116, 220, 107, 32));
        jButton1.setBounds(new Rectangle(256, 42, 83, 38));
        jButton1.setText("查看");
        jButton1.addActionListener(new project_Info_jButton1_actionAdapter(this));
        jButton2.setBounds(new Rectangle(393, 45, 86, 35));
        jButton2.setText("删除");
        jButton2.addActionListener(new project_Info_jButton2_actionAdapter(this));
        jButton3.setBounds(new Rectangle(256, 194, 85, 37));
        jButton3.setText("添加");
        jButton3.addActionListener(new project_Info_jButton3_actionAdapter(this));
        jButton4.setBounds(new Rectangle(395, 194, 87, 38));
        jButton4.setText("退出");
        jButton4.addActionListener(new project_Info_jButton4_actionAdapter(this));
        jTextField7.setBounds(new Rectangle(256, 111, 87, 41));
        jLabel7.setText("请输入项目编号来查找或删除");
        jLabel7.setBounds(new Rectangle(264, 67, 253, 56));
        jButton5.setBounds(new Rectangle(382, 113, 110, 39));
        jButton5.setText("清空所有信息");
        jButton5.addActionListener(new project_Info_jButton5_actionAdapter(this));
        this.getContentPane().add(jLabel1);
        jTextField5.setBounds(new Rectangle(115, 182, 108, 29));
        jTextField4.setBounds(new Rectangle(117, 136, 106, 31));
        jTextField3.setBounds(new Rectangle(118, 96, 107, 32));
        jTextField2.setBounds(new Rectangle(119, 54, 108, 33));
        jTextField1.setBounds(new Rectangle(120, 14, 79, 21));
        jLabel6.setText("参加人员角色");
        jLabel6.setBounds(new Rectangle(20, 219, 77, 47));
        jLabel5.setText("时间*");
        jLabel5.setBounds(new Rectangle(28, 178, 54, 37));
        jLabel4.setText("经费*(元)");
        jLabel4.setBounds(new Rectangle(26, 131, 59, 33));
        jLabel3.setText("项目来源");
        jLabel3.setBounds(new Rectangle(26, 95, 53, 23));
        this.getContentPane().add(jLabel2);
        this.getContentPane().add(jLabel3);
        this.getContentPane().add(jLabel4);
        this.getContentPane().add(jLabel5);
        this.getContentPane().add(jLabel6);
        this.getContentPane().add(jTextField1);
        this.getContentPane().add(jTextField2);
        this.getContentPane().add(jButton1);
        this.getContentPane().add(jButton2);
        this.getContentPane().add(jTextField7);
        this.getContentPane().add(jLabel7);
        this.getContentPane().add(jButton3);
        this.getContentPane().add(jButton4);
        this.getContentPane().add(jButton5);
        this.getContentPane().add(jTextField3);
        this.getContentPane().add(jTextField4);
        this.getContentPane().add(jTextField5);
        this.getContentPane().add(jTextField6);
        jLabel2.setText("项目名称*");
        jLabel2.setBounds(new Rectangle(24, 48, 64, 33));
    }

    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JLabel jLabel4 = new JLabel();
    JLabel jLabel5 = new JLabel();
    JLabel jLabel6 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JTextField jTextField2 = new JTextField();
    JTextField jTextField3 = new JTextField();
    JTextField jTextField4 = new JTextField();
    JTextField jTextField5 = new JTextField();
    JTextField jTextField6 = new JTextField();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JButton jButton3 = new JButton();
    JButton jButton4 = new JButton();
    JTextField jTextField7 = new JTextField();
    JLabel jLabel7 = new JLabel();
    JButton jButton5 = new JButton();
    public void jButton1_actionPerformed(ActionEvent e) {
               Connection con;
                Statement sql;
                ResultSet rs;
                String queryString;
                if(!jTextField7.getText().equals(""))
                queryString ="select * from 项目信息 where 项目编号=" +Integer.parseInt(jTextField7.getText());
                else {
                     queryString="";
                     JOptionPane.showMessageDialog(null, "请输入项目编号查看,请确认后认真填写", "提示框",
                                             JOptionPane.INFORMATION_MESSAGE);
                }
                try {
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                } catch (java.lang.ClassNotFoundException ee) {
                    System.err.print("class not find!");
                    System.err.println(ee.getMessage());
                }


                try {
                    con = DriverManager.getConnection("jdbc:odbc:scince", "", "");
                    sql = con.createStatement();
                    rs=sql.executeQuery(queryString);
                    if(rs.next()){
                        jTextField1.setText(Integer.toString(rs.getInt(1)));
                        jTextField2.setText(rs.getString(2));
                        jTextField3.setText(rs.getString(3));
                        jTextField4.setText(Integer.toString(rs.getInt(4)));
                        jTextField5.setText(rs.getString(5));
                        jTextField6.setText(rs.getString(6));

                    }
                    else {JOptionPane.showMessageDialog(null, "没有找到您要求的项目,请重新填写!", "提示框",
                                             JOptionPane.INFORMATION_MESSAGE);}
                    con.close();
        } catch (SQLException ex) {}
    }

    public void jButton2_actionPerformed(ActionEvent e) {
                        Connection con;
                        Statement sql;
                        ResultSet rs;
                        String queryString;// 删除语句
                       String queryString1;//查找确认语句
                        if(!jTextField7.getText().equals(""))
                        {
                            queryString ="DELETE from 项目信息 where 项目编号=" +Integer.parseInt(jTextField7.getText());
                            queryString1="select * from 项目信息 where 项目编号=" +Integer.parseInt(jTextField7.getText());
                        }
                    else
                       {  queryString="";
                           JOptionPane.showMessageDialog(null, "请输入内容,请确认后认真填写", "提示框",
                                             JOptionPane.INFORMATION_MESSAGE);


                       }
                        try {
                            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                        } catch (java.lang.ClassNotFoundException ee) {
                            System.err.print("class not find!");
                            System.err.println(ee.getMessage());
                }
                try {
                   con = DriverManager.getConnection("jdbc:odbc:scince", "", "");
                   sql = con.createStatement();
                   rs=sql.executeQuery(queryString1);
                   if(rs.next())
                       JOptionPane.showMessageDialog(null, "删除成功!", "提示框",
                                             JOptionPane.INFORMATION_MESSAGE);
                   else
                       JOptionPane.showMessageDialog(null, "没有找到您要删除的项目!", "提示框",
                                             JOptionPane.INFORMATION_MESSAGE);
                     sql.executeUpdate(queryString);
                     con.close();
                    jTextField7.setText("");

               } catch (SQLException ex) {}

    }

    public void jButton3_actionPerformed(ActionEvent e) {
                               Connection con;
                               Statement sql;
                               String queryString;
                               if(!jTextField1.getText().equals(""))
      {
          queryString ="INSERT INTO 项目信息 VALUES('"+Integer.parseInt(jTextField1.getText())+"','"+jTextField2.getText()+"','"+jTextField3.getText()+"','"+Integer.parseInt(jTextField4.getText())+"','"+jTextField5.getText()+"','"+jTextField6.getText()+"')";
          JOptionPane.showMessageDialog(null, "添加成功!", "提示框",
                                             JOptionPane.INFORMATION_MESSAGE);
      }
                              else {
                                      JOptionPane.showMessageDialog(null, "项目编号为必填信息,请添加完整后在添加!", "提示框",
                                             JOptionPane.INFORMATION_MESSAGE);
                                      queryString="";
                                  }
                          try {
                                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                               } catch (java.lang.ClassNotFoundException ee) {
                                   System.err.print("class not find!");
                                   System.err.println(ee.getMessage());
                       }
                       try {
                          con = DriverManager.getConnection("jdbc:odbc:scince", "", "");
                          con.setAutoCommit(false);
                          sql = con.createStatement();
                          sql.executeUpdate(queryString);
                          con.commit();
                          con.close();
                          jTextField1.setText("");
               jTextField2.setText("");
               jTextField3.setText("");
               jTextField4.setText("");
               jTextField5.setText("");
               jTextField6.setText("");

       } catch (SQLException ex) {}
    }

    public void jButton4_actionPerformed(ActionEvent e) {
this.dispose();
    }

    public void jButton5_actionPerformed(ActionEvent e) {
                        jTextField1.setText("");
                       jTextField2.setText("");
                       jTextField3.setText("");
                       jTextField4.setText("");
                       jTextField5.setText("");
                        jTextField6.setText("");
                        jTextField7.setText("");
    }


}


class project_Info_jButton5_actionAdapter implements ActionListener {
    private project_Info adaptee;
    project_Info_jButton5_actionAdapter(project_Info adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton5_actionPerformed(e);
    }
}


class project_Info_jButton4_actionAdapter implements ActionListener {
    private project_Info adaptee;
    project_Info_jButton4_actionAdapter(project_Info adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton4_actionPerformed(e);
    }
}


class project_Info_jButton3_actionAdapter implements ActionListener {
    private project_Info adaptee;
    project_Info_jButton3_actionAdapter(project_Info adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton3_actionPerformed(e);
    }
}


class project_Info_jButton2_actionAdapter implements ActionListener {
    private project_Info adaptee;
    project_Info_jButton2_actionAdapter(project_Info adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton2_actionPerformed(e);
    }
}


class project_Info_jButton1_actionAdapter implements ActionListener {
    private project_Info adaptee;
    project_Info_jButton1_actionAdapter(project_Info adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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