1. 程式人生 > >適合中職學生學生管理系統的研發(java+jdbc+mysql)(三)

適合中職學生學生管理系統的研發(java+jdbc+mysql)(三)

登陸成功之後顯示新增和查詢的操作,這裡面新增的操作,是實現了監聽之後重新的新增的方法,與LoginActivity實現分離,這裡面AddLayout做新增的介面和資料庫新增的操作

public    class ActionListenerImp implements java.awt.event.ActionListener{
    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("點選了新增");

        AddLayout add=new AddLayout ();
     
    }
}

那讓我們來具體看看這這個類,主要是新增介面的實現和介面新增的操作操作資料庫,實現新增的操作(BaseDao是實現資料連線資料增刪改查的操作)


public class Add extends JFrame {
    private static final long serialVersionUID = -1928970409928880648L;

    //String name, String sex, int age, String phone, String address
    JLabel jlnumber = new JLabel("姓名:");
    JLabel jlname = new JLabel("性別:");
    JLabel jlsex = new JLabel("年齡:");

    JLabel phone = new JLabel("電話:");
    JLabel address = new JLabel("地址:");

    JTextField jtname = new JTextField("",20);
    JTextField jtsexa = new JTextField("",20);
    JTextField jtage = new JTextField("",20);

    JTextField jtphone = new JTextField("",20);
    JTextField jtaddress = new JTextField("",20);

    JButton buttonadd = new JButton("新增");



    public Add() {
        JPanel jpnumber = new JPanel();
        JPanel jpname = new JPanel();
        JPanel jpsex = new JPanel();
        JPanel jpphone = new JPanel();
        JPanel jpaddress = new JPanel();

        jpnumber.add(jlnumber);
        jpnumber.add(jtname);

        jpname.add(jlname);
        jpname.add(jtsexa);

        jpsex.add(jlsex);
        jpsex.add(jtage);

        jpphone.add(phone);
        jpphone.add(jtphone);
        jpaddress.add(address);
        jpaddress.add(jtaddress);

        this.add(buttonadd);





        buttonadd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String name = jtname.getText();
                String sex = jtsexa.getText();
                String age = jtage.getText();
                String phone = jtphone.getText();
                String address = jtaddress.getText();

                Student student=new Student(name,sex,Integer.parseInt(age),phone,address);


                BaseDao baseDao=new BaseDao();
                baseDao.getConnection();
                baseDao.AddStudentInfor(student);
            }
        });

        this.setTitle("新增學生資訊");
        this.setLayout(new GridLayout(9,1));
        this.add(jpnumber);
        this.add(jpname);
        this.add(jpsex);
        this.add(jpphone);
        this.add(jpaddress);

        this.setLocation(400,300);
        this.setSize(350,300);
        this.setVisible(true);
    }

}