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

📄 studentinfopanel.java

📁 学生信息管理实例 这里主要是运用Java和SQL Server2000来实现一个学生信息管理系统
💻 JAVA
字号:
package panel;

import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.util.StringTokenizer;

/**
 * <p>Title: 学生信息管理系统</p>
 * <p>Description: 对学生信息、学生成绩进行管理</p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author 苏年乐
 * @version 1.0
 */

/**
 * 用于输入和显示学生信息的JPanel
 */
public class StudentInfoPanel
    extends JPanel {
  XYLayout xYLayout1 = new XYLayout();
  JLabel jLabel1 = new JLabel();
  JTextField nameField = new JTextField();
  JLabel jLabel2 = new JLabel();
  JTextField idField = new JTextField();
  JLabel jLabel3 = new JLabel();
  JComboBox sexComboBox = new JComboBox();
  JLabel jLabel4 = new JLabel();
  JTextField nationTextField = new JTextField();
  JLabel jLabel5 = new JLabel();
  JTextField yearField = new JTextField();
  JLabel jLabel6 = new JLabel();
  JTextField monthField = new JTextField();
  JLabel jLabel7 = new JLabel();
  JTextField dayField = new JTextField();
  JLabel jLabel8 = new JLabel();

  public StudentInfoPanel() {
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
    jLabel1.setText("姓名");
    this.setLayout(xYLayout1);
    this.setOpaque(true);
    nameField.setFont(new java.awt.Font("Dialog", 0, 12));
    nameField.setText("");
    jLabel2.setFont(new java.awt.Font("Dialog", 0, 12));
    jLabel2.setText("学号");
    idField.setFont(new java.awt.Font("Dialog", 0, 12));
    idField.setText("");
    jLabel3.setFont(new java.awt.Font("Dialog", 0, 12));
    jLabel3.setText("性别");
    jLabel4.setFont(new java.awt.Font("Dialog", 0, 12));
    jLabel4.setText("民族");
    nationTextField.setFont(new java.awt.Font("Dialog", 0, 12));
    nationTextField.setText("");
    jLabel5.setFont(new java.awt.Font("Dialog", 0, 12));
    jLabel5.setText("出生日期");
    yearField.setFont(new java.awt.Font("Dialog", 0, 12));
    yearField.setText("");
    jLabel6.setFont(new java.awt.Font("Dialog", 0, 12));
    jLabel6.setText("年");
    monthField.setFont(new java.awt.Font("Dialog", 0, 12));
    monthField.setText("");
    jLabel7.setFont(new java.awt.Font("Dialog", 0, 12));
    jLabel7.setText("月");
    dayField.setFont(new java.awt.Font("Dialog", 0, 12));
    dayField.setText("");
    jLabel8.setFont(new java.awt.Font("Dialog", 0, 12));
    jLabel8.setText("日");

    sexComboBox.addItem("男");
    sexComboBox.addItem("女");
    sexComboBox.setFont(new java.awt.Font("Dialog", 0, 12));
    this.add(jLabel1, new XYConstraints(19, 48, 48, 30));
    this.add(nameField, new XYConstraints(75, 52, 73, 27));
    this.add(jLabel2, new XYConstraints(196, 50, 51, 25));
    this.add(idField, new XYConstraints(251, 49, 91, 30));
    this.add(jLabel3, new XYConstraints(17, 104, 41, 24));
    this.add(sexComboBox, new XYConstraints(77, 106, 69, 24));
    this.add(jLabel4, new XYConstraints(195, 108, -1, 23));
    this.add(nationTextField, new XYConstraints(251, 106, 90, 24));
    this.add(jLabel5, new XYConstraints(12, 160, 59, 28));
    this.add(yearField, new XYConstraints(83, 163, 69, 27));
    this.add(jLabel6, new XYConstraints(162, 165, 35, 18));
    this.add(monthField, new XYConstraints(193, 163, 43, 27));
    this.add(jLabel7, new XYConstraints(247, 164, 25, 21));
    this.add(dayField, new XYConstraints(267, 163, 63, 27));
    this.add(jLabel8, new XYConstraints(343, 163, 22, 25));

    this.setVisible(true);
  }

  /**
   * 检查所有需要填入的项是否已经填满
   * @return boolean
   */
  public boolean check() {
    if (this.idField.getText().trim().equals("") ||
        this.nameField.getText().trim().equals("") ||
        ( (String)this.sexComboBox.getSelectedItem()).trim().equals("") ||
        this.nationTextField.getText().trim().equals("") ||
        this.yearField.getText().trim().equals("") ||
        this.monthField.getText().trim().equals("") ||
        this.dayField.getText().trim().equals(""))return false;
    else return true;
  }

  public String getID() {
    return this.idField.getText().trim();
  }

  public String getName() {
    return this.nameField.getText().trim();
  }

  public String getSex() {
    return ( (String)this.sexComboBox.getSelectedItem()).trim();
  }

  public String getNation() {
    return this.nationTextField.getText().trim();
  }

  public String getBirthDay() {
    String year = this.yearField.getText().trim();
    String month = this.monthField.getText().trim();
    String day = this.dayField.getText().trim();
    return year + "-" + month + "-" + day;
  }

  public void setID(String id) {
    this.idField.setText(id);
  }

  public void setName(String name) {
    this.nameField.setText(name);
  }

  public void setSex(String sex) {
    this.sexComboBox.setSelectedItem(sex);
  }

  public void setNation(String nation) {
    this.nationTextField.setText(nation);
  }

  public void setBirthDay(String birthday) {
    StringTokenizer st = new StringTokenizer(birthday, "-");
    String year = st.nextToken();
    String month = st.nextToken();
    String day = st.nextToken();
    this.yearField.setText(year);
    this.monthField.setText(month);
    this.dayField.setText(day);
  }

  public void clear() {
    this.idField.setText("");
    this.nameField.setText("");
    this.sexComboBox.setSelectedItem(null);
    this.nationTextField.setText("");
    this.yearField.setText("");
    this.monthField.setText("");
    this.dayField.setText("");
  }

  public void setIDEditEnable(boolean b) {
    this.idField.setEnabled(b);
  }

  public void setEditEnable(boolean b) {
    this.idField.setEnabled(b);
    this.nameField.setEnabled(b);
    this.sexComboBox.setEnabled(b);
    this.nationTextField.setEnabled(b);
    this.yearField.setEnabled(b);
    this.monthField.setEnabled(b);
    this.dayField.setEnabled(b);
  }

}

⌨️ 快捷键说明

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