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

📄 addstudentframe.java~140~

📁 java(Swing) access做的成绩管理系统
💻 JAVA~140~
字号:
package edu.xscj.business;

import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import edu.xscj.bean.*;
import java.util.Date;
import java.text.DateFormat;
import edu.xscj.action.AddStudentAction;
import edu.xscj.dialog.*;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.text.SimpleDateFormat;
import java.text.*;

public class AddStudentFrame extends JFrame {
    public AddStudentFrame() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.getContentPane().setLayout(xYLayout1);
        lbstuNo.setText("学号");
        lbName.setText("姓名");
        lbBirth.setText("出生日期");
        lbSex.setText("性别");
        radioSexBoy.setActionCommand("男");
        radioSexBoy.setText("男");
        radioSexGirl.setActionCommand("女");
        radioSexGirl.setText("女");
        btnReset.setText("重填");
        btnReset.addActionListener(new AddStudentFrame_btnReset_actionAdapter(this));
        lbYear.setText("年");
        lbMonth.setText("月");
        lbDay.setText("日");
        for (int i = 1960; i < 2100; i++) {
            boxYear.addItem(Integer.toString(i));
        }
        for (int m = 1; m < 13; m++) {
            boxMonth.addItem(Integer.toString(m));
        }
        for (int d = 1; d < 32; d++) {
            boxDay.addItem(Integer.toString(d));
        }
        btnSubmit.addActionListener(new AddStudentFrame_btnSubmit_actionAdapter(this));

        this.getContentPane().add(txtstuName,
                                  new XYConstraints(171, 80, 150, 29));
        this.getContentPane().add(txtStuNo, new XYConstraints(171, 33, 150, 27));
        this.getContentPane().add(radioSexBoy,
                                  new XYConstraints(171, 135, 47, 29));
        this.getContentPane().add(radioSexGirl,
                                  new XYConstraints(259, 135, 61, 28));
        this.getContentPane().add(btnSubmit, new XYConstraints(123, 251, 62, 24));
        btnSubmit.setText("确定");
        sexGroup.add(radioSexBoy);
        sexGroup.add(radioSexGirl);
        this.getContentPane().add(lbBirth, new XYConstraints(51, 192, 55, 19));

        this.getContentPane().add(lbstuNo, new XYConstraints(61, 33, 36, 26));
        this.getContentPane().add(lbName, new XYConstraints(61, 87, -1, -1));
        this.getContentPane().add(lbSex, new XYConstraints(63, 140, -1, -1));
        this.getContentPane().add(btnReset, new XYConstraints(241, 249, -1, -1));
        this.getContentPane().add(lbDay, new XYConstraints(300, 194, -1, -1));
        this.getContentPane().add(boxMonth, new XYConstraints(251, 189, -1, 20));
        this.getContentPane().add(boxDay, new XYConstraints(330, 189, -1, 21));
        this.getContentPane().add(boxYear, new XYConstraints(157, 189, 55, 21));
        this.getContentPane().add(lbYear, new XYConstraints(129, 192, -1, -1));
        this.getContentPane().add(lbMonth, new XYConstraints(230, 191, -1, -1));
        this.setSize(420, 350);
        this.setResizable(false);
        this.setTitle("添加学生信息");
    }

    XYLayout xYLayout1 = new XYLayout();
    JLabel lbstuNo = new JLabel();
    JTextField txtStuNo = new JTextField();
    JTextField txtstuName = new JTextField();
    JLabel lbName = new JLabel();
    JLabel lbBirth = new JLabel();
    JLabel lbSex = new JLabel();
    JRadioButton radioSexBoy = new JRadioButton();
    JRadioButton radioSexGirl = new JRadioButton();
    ButtonGroup sexGroup = new ButtonGroup();
    JButton btnSubmit = new JButton();
    JButton btnReset = new JButton();
    JComboBox boxYear = new JComboBox();
    JComboBox boxMonth = new JComboBox();
    JComboBox boxDay = new JComboBox();
    JLabel lbYear = new JLabel();
    JLabel lbMonth = new JLabel();
    JLabel lbDay = new JLabel();
    public void btnReset_actionPerformed(ActionEvent e) {
        txtStuNo.setText("");
        txtstuName.setText("");
    }

    public void btnSubmit_actionPerformed(ActionEvent e) {
        String stuNo = txtStuNo.getText();
        String stuName = txtstuName.getText();
        if(stuNo.equals("")||stuName.equals("")){
            JOptionPane.showMessageDialog(this, "学号和姓名不能为空!", "温心提示",
                                          JOptionPane.
                                          INFORMATION_MESSAGE);

        }
        if(sexGroup.getSelection()==null||this.sexGroup.getSelection().equals("")){
            JOptionPane.showMessageDialog(this, "添加学生成功!", "温心提示",
                                          JOptionPane.
                                          INFORMATION_MESSAGE);

        }
        String sex = sexGroup.getSelection().getActionCommand();

        String year = (String) boxYear.getSelectedItem();
        String month = (String) boxMonth.getSelectedItem();
        String day = (String) boxDay.getSelectedItem();

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date birthday = null;
        try {
            birthday = format.parse(year + "-" + month + "-" + day);
        } catch (ParseException ex) {
        }

        Student student = new Student();
        student.setStuNo(stuNo);
        student.setStuName(stuName);
        student.setStuSex(sex);
        student.setStuBirthday(new java.sql.Date(birthday.getTime()));

        AddStudentAction stuAction = new AddStudentAction();
        String str = stuAction.addStudent(student);
        if (str.equals("sucess")) {
            /*
             AlertDialog dialog = new AlertDialog(this, "学生添加成功!!", true);
             Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
             Dimension size = dialog.getSize();
             dialog.setLocation((dimension.width - size.width) / 2,
                                (dimension.height - size.height) / 2);

             dialog.setSize(200, 100);
             dialog.setVisible(true);*/
            JOptionPane.showMessageDialog(this, "添加学生成功!", "温心提示",
                                          JOptionPane.
                                          INFORMATION_MESSAGE);
        } else if (str.equals("failer")) {
            JOptionPane.showMessageDialog(this, "添加学生失败!!", "温心提示",
                                          JOptionPane.
                                          INFORMATION_MESSAGE);

        }
    }
}


class AddStudentFrame_btnSubmit_actionAdapter implements ActionListener {
    private AddStudentFrame adaptee;
    AddStudentFrame_btnSubmit_actionAdapter(AddStudentFrame adaptee) {
        this.adaptee = adaptee;
    }

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


class AddStudentFrame_btnReset_actionAdapter implements ActionListener {
    private AddStudentFrame adaptee;
    AddStudentFrame_btnReset_actionAdapter(AddStudentFrame adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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