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

📄 staff_add.java~5~

📁 javaGUI编写的人事管理系统(毕业学生答辩可参考)
💻 JAVA~5~
字号:
package project;


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.DefaultTableModel;
import java.sql.ResultSet;
import java.awt.Dimension;
import java.awt.Rectangle;

public class Staff_add
    extends JPanel implements All_view{
  public Staff_add() {
    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  Object[][] dep =null;
  Object[][] position=null;
  int partid=0,positionid=0;
  JFrame mainframe = null;
  String showMessage = null;
  JLabel id = new JLabel();
  JLabel name = new JLabel();
  JTextField nameText = new JTextField();
  JLabel jLabel4 = new JLabel();
  JTextField birthText = new JTextField();
  JLabel jLabel1 = new JLabel();
  ButtonGroup buttonGroup1 = new ButtonGroup();
  JRadioButton male = new JRadioButton();
  JRadioButton female = new JRadioButton();
  JTextField idText = new JTextField();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JLabel jLabel5 = new JLabel();
  JTextField telText = new JTextField();
  JLabel jLabel6 = new JLabel();
  JTextField addressText = new JTextField();
  JLabel jLabel7 = new JLabel();
  JTextField hire_dateText = new JTextField();
  JLabel jLabel8 = new JLabel();
  JTextField contract_expireText = new JTextField();
  JLabel jLabel9 = new JLabel();
  JTextField salaryText = new JTextField();
  JLabel jLabel10 = new JLabel();
  JTextField educationText = new JTextField();
  JButton okbtn = new JButton();
  JButton resetbtn = new JButton();
  JComboBox partBox = new JComboBox();
  JComboBox positionBox = new JComboBox();
  JLabel showMsg = new JLabel();
  JLabel jLabel11 = new JLabel();
  JButton jButton1 = new JButton();
  JScrollPane jScrollPane1 = new JScrollPane();
  JTable jTable1=null;


  public void tb(){
    DataBase db3 = new DataBase();
    String sql = "select top 1 employee_id,name,dep_id,position_id from employee_table order by employee_id desc";
    ResultSet rs = db3.executeQuery(sql);
    DataMap mp = new DataMap(rs);
    Object[][] obj = mp.get_DataMap_Array();
    String[] colnames = {
        "工号", "姓名", "部门ID", "职位ID"};
    DefaultTableModel dm = new DefaultTableModel(obj, colnames);
    jTable1 = new JTable(dm);
    jScrollPane1.setBounds(new Rectangle(56, 442, 216, 44));
    this.add(jScrollPane1);
    jScrollPane1.getViewport().add(jTable1);
  }

  public  Staff_add(JFrame mainframe) {
    this.mainframe = mainframe;
    try {
      jbInit();
      setPanelPosOnDesktop(this.mainframe);
    }
    catch (Exception exception) {
      exception.printStackTrace();
    }
  }

    private void jbInit() throws Exception {
      this.setLayout(null);
      setSize(new Dimension(877, 612));
      id.setText("工号:");
      id.setBounds(new Rectangle(54, 86, 38, 28));
      name.setText("姓名:");
      name.setBounds(new Rectangle(303, 88, 39, 28));
      nameText.setText("");
      nameText.setBounds(new Rectangle(402, 82, 92, 28));
      jLabel4.setText("出生年月:");
      jLabel4.setBounds(new Rectangle(537, 83, 74, 28));
      birthText.setBounds(new Rectangle(615, 83, 103, 28));
      jLabel1.setText("性别:");
      jLabel1.setBounds(new Rectangle(542, 132, 55, 28));
      male.setText("男");
      male.setBounds(new Rectangle(616, 128, 53, 28));
      female.setText("女");
      female.setBounds(new Rectangle(677, 127, 42, 28));
      idText.setBounds(new Rectangle(133, 83, 83, 28));
      jLabel2.setText("部门ID:");
      jLabel2.setBounds(new Rectangle(54, 140, 61, 28));
      Staff_C sm = new Staff_C();
      dep = sm.depart();
      for (int i = 0; i < dep.length; i++) {
        partBox.addItem(dep[i][1].toString());
      }
      jLabel3.setText("职务ID:");
      jLabel3.setBounds(new Rectangle(303, 140, 79, 28));
      jLabel5.setText("联系电话:");
      jLabel5.setBounds(new Rectangle(54, 193, 74, 28));
      telText.setText("");
      telText.setBounds(new Rectangle(133, 190, 141, 28));
      jLabel6.setText("家庭住址:");
      jLabel6.setBounds(new Rectangle(303, 195, 84, 28));
      addressText.setText("");
      addressText.setBounds(new Rectangle(402, 189, 224, 28));
      jLabel7.setText("进司日期:");
      jLabel7.setBounds(new Rectangle(54, 250, 76, 28));
      hire_dateText.setBounds(new Rectangle(133, 247, 103, 28));
      jLabel8.setText("合同到期日期:");
      jLabel8.setBounds(new Rectangle(303, 252, 91, 28));
      contract_expireText.setText("");
      contract_expireText.setBounds(new Rectangle(402, 246, 103, 28));
      jLabel9.setText("工资底薪:");
      jLabel9.setBounds(new Rectangle(54, 303, 72, 28));
      salaryText.setText("");
      salaryText.setBounds(new Rectangle(133, 305, 101, 28));
      jLabel10.setText("本人学历:");
      jLabel10.setBounds(new Rectangle(303, 305, 87, 28));
      educationText.setText("");
      educationText.setBounds(new Rectangle(402, 304, 100, 28));
      okbtn.setBounds(new Rectangle(172, 370, 97, 28));
      okbtn.setText("确认");
      okbtn.addActionListener(new Staff_add_okbtn_actionAdapter(this));
      resetbtn.setText("重置");
      resetbtn.setBounds(new Rectangle(463, 368, 97, 28));
      resetbtn.addActionListener(new Staff_add_resetbtn_actionAdapter(this));
      partBox.setSelectedIndex( -1);
      partBox.setBounds(new Rectangle(133, 135, 91, 28));
      partBox.addItemListener(new Staff_add_partBox_itemAdapter(this));
      positionBox.setBounds(new Rectangle(402, 134, 110, 28));
      positionBox.addItemListener(new Staff_add_positionBox_itemAdapter(this));
      showMsg.setText("");
      showMsg.setBounds(new Rectangle(494, 34, 219, 25));
      jButton1.setBounds(new Rectangle(55, 418, 218, 23));
      jButton1.setText("最近录入记录");
      jLabel11.setFont(new java.awt.Font("幼圆", Font.BOLD, 20));
      jLabel11.setForeground(new Color(85, 45, 25));
      jLabel11.setText("员 工 信 息 录 入");
      jLabel11.setBounds(new Rectangle(221, 25, 197, 45));

    this.add(jLabel11);
    this.add(id);
    this.add(jLabel2);
    this.add(jLabel5);
    this.add(jLabel7);
    this.add(jLabel9);
    this.add(jButton1);
    this.add(idText);
    this.add(partBox);
    this.add(telText);
    this.add(hire_dateText);
    this.add(salaryText);
    this.add(name);
    this.add(jLabel3);
    this.add(jLabel6);
    this.add(jLabel8);
    this.add(jLabel10);
    this.add(nameText);
    this.add(positionBox);
    this.add(addressText);
    this.add(contract_expireText);
    this.add(educationText);
    this.add(jLabel4);
    this.add(jLabel1);
    this.add(birthText);
    this.add(male);
    this.add(female);
    this.add(showMsg);
    this.add(okbtn);
    this.add(resetbtn);
    this.tb();


    buttonGroup1.add(male);
    buttonGroup1.add(female);
  }
 public void setPanelPosOnDesktop(JFrame frame) {
   this.setLocation( (((Frame1)frame).get_Container_width()- this.getSize().width) / 2,
                     (((Frame1)frame).get_Container_height()- this.getSize().height) / 2);
   }

   public void closeCurrentPanel(JFrame frame) {
      ((Frame1)frame).remove_panel();
   }

   public void set_focus() {
     nameText.requestFocus();
   }
   public void requestFocus(){
     set_focus();
  }

 public void clear(){
   //partBox.setSelectedIndex( -1);
   idText.setText("");
   nameText.setText("");
   birthText.setText("");
   addressText.setText("");
   hire_dateText.setText("");
   contract_expireText.setText("");
   telText.setText("");
   salaryText.setText("");
   educationText.setText("");
   this.tb();
 }

  public void okbtn_actionPerformed(ActionEvent e) {
    Staff_obj_M obj1 = new Staff_obj_M();
    Staff_C method = new Staff_C();
    obj1.setId(Integer.parseInt(idText.getText()));
    obj1.setName(nameText.getText());
    obj1.setBirth(birthText.getText());
    obj1.setAddress(addressText.getText());
    if(male.isSelected()){
      obj1.setSex(1);
    }else{
      obj1.setSex(0);
    }
    obj1.setDep(partid);
    obj1.setPosition(Integer.parseInt(position[positionBox.getSelectedIndex()][0].toString()));
    obj1.setHiredate(hire_dateText.getText());
    obj1.setContract(contract_expireText.getText());
    obj1.setTelephone(telText.getText());
    obj1.setSalary(Integer.parseInt(salaryText.getText()));
    obj1.setEducation(educationText.getText());
    int r = method.staff_add(obj1);
    if (r == 1) {
      showMessage = "输入数据成功!!";
    }
    else {
      showMessage = "输入数据失败!!";
    }
    showMsg.setText(showMessage);
    this.clear();
  }

  public void resetbtn_actionPerformed(ActionEvent e) {
    this.clear();

  }

  public void partBox_itemStateChanged(ItemEvent e) {
    int pname = partBox.getSelectedIndex();
    partid = Integer.parseInt(dep[pname][0].toString());
    Staff_C sm = new Staff_C();
    position =sm.position(partid);
    positionBox.removeAllItems();
    for(int i = 0; i< position.length;i++){
      positionBox.addItem(position[i][1].toString());
    }

  }

  public void positionBox_itemStateChanged(ItemEvent e) {

  }

}

class Staff_add_positionBox_itemAdapter
    implements ItemListener {
  private Staff_add adaptee;
  Staff_add_positionBox_itemAdapter(Staff_add adaptee) {
    this.adaptee = adaptee;
  }

  public void itemStateChanged(ItemEvent e) {
    adaptee.positionBox_itemStateChanged(e);
  }
}

class Staff_add_partBox_itemAdapter
    implements ItemListener {
  private Staff_add adaptee;
  Staff_add_partBox_itemAdapter(Staff_add adaptee) {
    this.adaptee = adaptee;
  }

  public void itemStateChanged(ItemEvent e) {

    adaptee.partBox_itemStateChanged(e);
  }
}

class Staff_add_resetbtn_actionAdapter
    implements ActionListener {
  private Staff_add adaptee;
  Staff_add_resetbtn_actionAdapter(Staff_add adaptee) {
    this.adaptee = adaptee;
  }

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

class Staff_add_okbtn_actionAdapter
    implements ActionListener {
  private Staff_add adaptee;
  Staff_add_okbtn_actionAdapter(Staff_add adaptee) {
    this.adaptee = adaptee;
  }

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

⌨️ 快捷键说明

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