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

📄 changeaward.java

📁 学生档案管理系统
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package 学生档案管理系统;/** * * @author Administrator */import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;class ChangeAward extends JDialog{    Statement ps;    ResultSet rs;    Connection con;    String url;    String strType;    String strEvent;    String strPTime;    String strPResult;        JPanel panel = new JPanel();         JPanel panelb = new JPanel();        JLabel labType = new JLabel();    JTextField txtType = new JTextField();    JLabel labEvent = new JLabel();    JTextField txtEvent = new JTextField();    JLabel labPTime = new JLabel();    JTextField txtPTime = new JTextField();    JLabel labPResult = new JLabel();    JTextField txtPResult = new JTextField();        JButton sure = new JButton();    JButton cancel = new JButton();           public ChangeAward(Frame frame, String title, boolean modal) {        super(frame, title, modal);        try {            jbInit();            pack();        }        catch (Exception ex) {            ex.printStackTrace();        }    }    public ChangeAward() {        this(null, "", true);    }    private void jbInit() throws Exception{        try {                try {                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");                    Connection con = DriverManager.getConnection("jdbc:odbc:学生档案","", "");                    ps = con.createStatement();                }                catch (Exception err) {                    String error = err.getMessage();                    JOptionPane.showMessageDialog(null, "连接数据库错误!");                }                try {                    String strSNum = "'"+MainFrame.strSNum+"'";                    String sqlStr = "Select * from 奖惩记录表 where 学号 ="+ strSNum;                    rs = ps.executeQuery(sqlStr);                      while(rs.next()){                        strType = rs.getString(2);                                                strEvent = rs.getString(3);                        strPTime = rs.getString(4);                        strPResult = rs.getString(5);                    }                    ps.close();                }                catch (SQLException sqle) {                    String error = sqle.getMessage();                    JOptionPane.showMessageDialog(null, error);                    sqle.printStackTrace();                }            }            catch (Exception ex) {                ex.getMessage();                String error = ex.getMessage();                JOptionPane.showMessageDialog(null, error);                ex.printStackTrace();            }        labType.setText("类      别");        txtType.setText(strType);        labEvent.setText("事      件");        txtEvent.setText(strEvent);        labPTime.setText("处理时间");        txtPTime.setText(strPTime);        labPResult.setText("处理结果");        txtPResult.setText(strPResult);                sure.setText("确定");        sure.addActionListener(new ChangeAward_sure_actionAdapter(this));        cancel.setText("取消");        cancel.addActionListener(new ChangeAward_cancel_actionAdapter(this));                panel.setBorder(BorderFactory.createLoweredBevelBorder());        panel.setLayout(new GridBagLayout());                LayoutUtil.add(panel,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,0,0,1,1,labType);        LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,1,0,1,0,1,1,txtType);        LayoutUtil.add(panel,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,2,0,1,1,labEvent);        LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,1,0,3,0,1,1,txtEvent);                LayoutUtil.add(panel,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,0,1,1,1,labPTime);        LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,1,0,1,1,1,1,txtPTime);        LayoutUtil.add(panel,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,2,1,1,1,labPResult);        LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,1,0,3,1,1,1,txtPResult);                panelb.setLayout(new GridBagLayout());        LayoutUtil.add(panelb,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,0,0,1,1,sure);        LayoutUtil.add(panelb,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0,0,1,0,1,1,cancel);                this.getContentPane().add(panel,BorderLayout.CENTER);        this.getContentPane().add(panelb,BorderLayout.SOUTH);        this.setBounds(100, 100, 400, 300);        this.setVisible(true);    }void cancel_actionPerformed(ActionEvent e) {        this.dispose();    }    void sure_actionPerformed(ActionEvent e) {            JOptionPane.showConfirmDialog(null,"确定修改?", "修改奖惩信息", JOptionPane.YES_NO_OPTION);            try {                try {                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");                    Connection con = DriverManager.getConnection("jdbc:odbc:学生档案","", "");                    ps = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);                }                catch (Exception err) {                    String error = err.getMessage();                    JOptionPane.showMessageDialog(null, "连接数据库错误!");                }                try {                    String strSNum = "'"+MainFrame.strSNum+"'";                    strType = "'"+txtType.getText().trim()+"'";                    strEvent = "'"+txtEvent.getText().trim()+"'";                    strPTime = "'"+txtPTime.getText().trim()+"'";                    strPResult = "'"+txtPResult.getText().trim()+"'";                                       String sqlStr = "Update 奖惩记录表 set 类别=" +strType +", 事件 ="+strEvent+", 处理时间="+strPTime+", 处理结果= "+strPResult+"where 学号="+strSNum;                    ps.execute(sqlStr);                                        ps.close();                                       JOptionPane.showMessageDialog(null, "修改成功");                    this.dispose();                }                catch (SQLException sqle) {                    String error = sqle.getMessage();                    JOptionPane.showMessageDialog(null, error);                    sqle.printStackTrace();                }            }            catch (Exception ex) {                ex.getMessage();                String error = ex.getMessage();                JOptionPane.showMessageDialog(null, error);                ex.printStackTrace();            }        }    }//}class ChangeAward_cancel_actionAdapter    implements java.awt.event.ActionListener {    ChangeAward adaptee;    ChangeAward_cancel_actionAdapter(ChangeAward adaptee) {        this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {        adaptee.cancel_actionPerformed(e);    }}class ChangeAward_sure_actionAdapter    implements java.awt.event.ActionListener {    ChangeAward adaptee;    ChangeAward_sure_actionAdapter(ChangeAward adaptee) {        this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {        adaptee.sure_actionPerformed(e);    }}

⌨️ 快捷键说明

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