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

📄 addfamily.java

📁 学生档案管理系统
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package 学生档案管理系统;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;/** * * @author Administrator */public class AddFamily extends JDialog{    Statement ps;    ResultSet rs;    Connection con;    String url;        JPanel panel = new JPanel();         JPanel panelb = new JPanel();    JLabel labName = new JLabel();    JTextField txtName = new JTextField();    JLabel labRelation = new JLabel();    JTextField txtRelation = new JTextField();    JLabel labPhoneNum = new JLabel();    JTextField txtPhoneNum = new JTextField();    JLabel labJobAddress = new JLabel();    JTextField txtJobAddress = new JTextField();        JButton sure = new JButton();    JButton cancel = new JButton();            public AddFamily(Frame frame, String title, boolean modal) {        super(frame, title, modal);        try {            jbInit();            pack();        }        catch (Exception ex) {            ex.printStackTrace();        }    }        public AddFamily() {        this(null, "", true);    }    private void jbInit() throws Exception{        labName.setText("姓      名 ");        labRelation.setText("与本人关系");        labPhoneNum.setText("联系电话");        labJobAddress.setText("所在单位");                sure.setText("确定");        sure.addActionListener(new addFamily_sure_actionAdapter(this));        cancel.setText("取消");        cancel.addActionListener(new addFamily_cancel_actionAdapter(this));                panel.setBorder(BorderFactory.createLoweredBevelBorder());        panel.setLayout(new GridBagLayout());                LayoutUtil.add(panel,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,0,0,1,1,labName);        LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,1,0,1,0,1,1,txtName);        LayoutUtil.add(panel,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,2,0,1,1,labRelation);        LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,1,0,3,0,1,1,txtRelation);                LayoutUtil.add(panel,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,0,1,1,1,labPhoneNum);        LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,1,0,1,1,1,1,txtPhoneNum);        LayoutUtil.add(panel,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,2,1,1,1,labJobAddress);        LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,1,0,3,1,1,1,txtJobAddress);                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+"'";                    String strName = "'"+txtName.getText().trim()+"'";                    String strRelation = "'"+txtRelation.getText().trim()+"'";                    String strJobAddress = "'"+txtJobAddress.getText().trim()+"'";                    String strPhoneNum = "'"+txtPhoneNum.getText().trim()+"'";                                       String sqlStr = "Insert Into 家庭成员表 (学号,姓名,与本人关系,电话,所在单位) " +                                "values(" + strSNum + "," + strName + "," + strRelation+ "," + strPhoneNum+ "," +strJobAddress+")";                    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 addFamily_cancel_actionAdapter    implements java.awt.event.ActionListener {    AddFamily adaptee;    addFamily_cancel_actionAdapter(AddFamily adaptee) {        this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {        adaptee.cancel_actionPerformed(e);    }}class addFamily_sure_actionAdapter    implements java.awt.event.ActionListener {    AddFamily adaptee;    addFamily_sure_actionAdapter(AddFamily adaptee) {        this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {        adaptee.sure_actionPerformed(e);    }}

⌨️ 快捷键说明

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