📄 paneladdstudents.java
字号:
jLabel12.setForeground(new java.awt.Color(255, 0, 0)); jLabel12.setBounds(532, 147, 140, 21); jLabel12.setFont(new java.awt.Font("宋体", 0, 12)); } { jLabel13 = new JLabel(); panelCenter.add(jLabel13); jLabel13.setText(" * "); jLabel13.setForeground(new java.awt.Color(255, 0, 0)); jLabel13.setBounds(532, 175, 140, 21); jLabel13.setFont(new java.awt.Font("宋体", 0, 12)); } { jLabel14 = new JLabel(); panelCenter.add(jLabel14); jLabel14.setText(" *"); jLabel14.setForeground(new java.awt.Color(255, 0, 0)); jLabel14.setBounds(602, 203, 21, 21); jLabel14.setFont(new java.awt.Font("宋体", 0, 12)); } } { panelDown = new JPanel(); this.add(panelDown, BorderLayout.SOUTH); panelDown.setBackground(new java.awt.Color(236, 233, 216)); { buttonSubmit = new JButton(); panelDown.add(buttonSubmit); buttonSubmit.setText("确认添加信息"); buttonSubmit.setFont(new java.awt.Font("宋体", 0, 12)); buttonSubmit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { buttonSubmitActionPerformed(evt); } }); } { buttonReset = new JButton(); panelDown.add(buttonReset); buttonReset.setText("重新填写信息"); buttonReset.setFont(new java.awt.Font("宋体", 0, 12)); buttonReset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { buttonResetActionPerformed(evt); } }); } } } catch (Exception e) { e.printStackTrace(); } } /** * 《确认添加信息》按钮事件处理 * * @param evt */ private void buttonSubmitActionPerformed(ActionEvent evt) { insert(); } /** * 《重新填写信息》按钮事件处理 * * @param evt */ private void buttonResetActionPerformed(ActionEvent evt) { initial(); } /** * 《所在班级》选项的的事件处理 * * @param evt */ private void comboBoxClassItemStateChanged(ItemEvent evt) { if (this.comboBoxClass.getItemCount() != 0) { if (this.comboBoxClass.getSelectedItem().toString().equals("<添加新班级>")) { if (!ObjectClasses.checkBoxMenuItemAddClasses.isSelected()) { ObjectClasses.checkBoxMenuItemAddClasses.setSelected(true); } LogChecked.tabbedSelected(); tabbedPane.setSelectedComponent(ObjectClasses.panelAddClasses); comboBoxClass.setSelectedIndex(0); } } } /** * 页面初始化方法 */ private void initial() { this.textFieldID.setText(""); this.textFieldName.setText(""); this.comboBoxSex.setSelectedIndex(0); this.comboBoxAge.setSelectedIndex(0); this.textFieldPhone.setText(""); this.textFieldHandset.setText(""); this.textFieldAddress.setText(""); this.comboBoxNative.setSelectedIndex(0); this.comboBoxEdu.setSelectedIndex(0); this.comboBoxMarry.setSelectedIndex(0); this.comboBoxWork.setSelectedIndex(0); this.comboBoxStage.setSelectedIndex(0); this.comboBoxClass.setSelectedIndex(0); this.comboBoxY.setSelectedItem(date[0]); this.comboBoxM.setSelectedItem(date[1]); this.comboBoxD.setSelectedItem(date[2]); this.textAreaLike.setText(""); this.textAreaRemarks.setText(""); } /** * 获取表单并进行验证,向数据库插入数据的方法 */ private void insert() { /* * 《学生编号》 */ String student_ID = this.textFieldID.getText().trim(); if (!FormChecked.mustNotNull("学生编号", student_ID)) { this.textFieldID.requestFocus(); return; } if (!FormChecked.mustNumber("学生编号", student_ID)) { this.textFieldID.requestFocus(); return; } if (!FormChecked.charEqualNumber("学生编号", student_ID, 5)) { this.textFieldID.requestFocus(); return; } if (!FormChecked.mustNotRepeat("学生编号", student_ID, "Students", "Student_ID")) { this.textFieldID.requestFocus(); return; } /* * 《学生姓名》 */ String student_Name = this.textFieldName.getText().trim(); if (!FormChecked.mustNotNull("学生姓名", student_Name)) { this.textFieldName.requestFocus(); return; } if (!FormChecked.charBigNumber("学生姓名", student_Name, 2)) { this.textFieldName.requestFocus(); return; } if (!FormChecked.charCheck("学生姓名", student_Name)) { this.textFieldName.requestFocus(); return; } /* * 《学生性别》 */ String student_Sex = this.comboBoxSex.getSelectedItem().toString(); if (!FormChecked.mustSelect("学生性别", student_Sex)) { this.comboBoxSex.requestFocus(); return; } /* * 《学生年龄》 */ String student_Age = this.comboBoxAge.getSelectedItem().toString(); if (!FormChecked.mustSelect("学生年龄", student_Age)) { this.comboBoxAge.requestFocus(); return; } /* * 《家庭电话》 */ String student_Phone = this.textFieldPhone.getText().trim(); if (!FormChecked.mustNumber("家庭电话", student_Phone)) { this.textFieldPhone.requestFocus(); return; } /* * 《手机号码》 */ String student_Handset = this.textFieldHandset.getText().trim(); if (!FormChecked.mustNumber("手机号码", student_Handset)) { this.textFieldHandset.requestFocus(); return; } /* * 《家庭住址》 */ String student_Address = this.textFieldAddress.getText().trim(); if (!FormChecked.mustNotNull("家庭住址", student_Address)) { this.textFieldAddress.requestFocus(); return; } if (!FormChecked.charCheck("家庭住址", student_Address)) { this.textFieldAddress.requestFocus(); return; } /* * 《学生籍贯》 */ String student_Native = this.comboBoxNative.getSelectedItem().toString(); if (!FormChecked.mustSelect("学生籍贯", student_Native)) { this.comboBoxNative.requestFocus(); return; } /* * 《学生学历》 */ String student_Edu = this.comboBoxEdu.getSelectedItem().toString(); if (!FormChecked.mustSelect("学生学历", student_Edu)) { this.comboBoxEdu.requestFocus(); return; } /* * 《婚姻状况》 */ String student_Marry = this.comboBoxMarry.getSelectedItem().toString(); if (!FormChecked.mustSelect("婚姻状况", student_Marry)) { this.comboBoxMarry.requestFocus(); return; } /* * 《工作经验》 */ String student_Work = this.comboBoxWork.getSelectedItem().toString(); if (!FormChecked.mustSelect("工作经验", student_Work)) { this.comboBoxWork.requestFocus(); return; } /* * 《学习阶段》 */ String student_Stage = this.comboBoxStage.getSelectedItem().toString(); if (!FormChecked.mustSelect("学习阶段", student_Stage)) { this.comboBoxStage.requestFocus(); return; } /* * 《所在班级》 */ String student_Class = this.comboBoxClass.getSelectedItem().toString(); if (!FormChecked.mustSelect("所在班级", student_Class)) { this.comboBoxClass.requestFocus(); return; } /* * 《入学时间》 */ String date_Y = this.comboBoxY.getSelectedItem().toString(); String date_M = this.comboBoxM.getSelectedItem().toString(); String date_D = this.comboBoxD.getSelectedItem().toString(); String student_StartClassTime = date_Y + "-" + date_M + "-" + date_D; /* * 《兴趣爱好》 */ String student_Like = this.textAreaLike.getText(); if (!FormChecked.charCheck("兴趣爱好", student_Like)) { this.textAreaLike.requestFocus(); return; } /* * 《学生点评》 */ String student_Remarks = this.textAreaRemarks.getText(); if (!FormChecked.charCheck("学生点评", student_Remarks)) { this.textAreaRemarks.requestFocus(); return; } String teacher_InsertTime = SQLOperate.getPreciseDate(); String teacher_UpdateTime = SQLOperate.getPreciseDate(); String teacher_UpdateName = "边疆"; /** * 生成 SQL 语句 */ sqlStr = "Insert into Students" + "(" + "Student_ID," + "Student_Name," + "Student_Sex," + "Student_Age," + "Student_Phone," + "Student_Handset," + "Student_Address," + "Student_Native," + "Student_Edu," + "Student_Marry," + "Student_Work," + "Student_Stage," + "Student_Class," + "Student_StartClassTime," + "Student_Like," + "Student_Remarks," + "Student_InsertTime," + "Student_UpdateTime," + "Student_UpdateName" + ")" + "values" + "(" + "'" + student_ID + "'," + "'" + student_Name + "'," + "'" + student_Sex + "'," + "'" + student_Age + "'," + "'" + student_Phone + "'," + "'" + student_Handset + "'," + "'" + student_Address + "'," + "'" + student_Native + "'," + "'" + student_Edu + "'," + "'" + student_Marry + "'," + "'" + student_Work + "'," + "'" + student_Stage + "'," + "'" + student_Class + "'," + "'" + student_StartClassTime + "'," + "'" + student_Like + "'," + "'" + student_Remarks + "'," + "'" + teacher_InsertTime + "'," + "'" + teacher_UpdateTime + "'," + "'" + teacher_UpdateName + "'" + ")"; // System.out.println(sqlStr); st = SQLOperate.getStatement(); try { st.executeUpdate(sqlStr); } catch (SQLException e) { // e.printStackTrace(); SQLOperate.closeST(); FormChecked.lose("添加学生", "添加失败!数据库访问错误!"); return; } FormChecked.success("添加学生", "成功添加学生信息"); SQLOperate.selectAllFromData("Students", tableStudents); ObjectClasses.tableStudentsRowCountFile = ObjectClasses.tableStudentsRowFile.setTableRowFile(ObjectClasses.tableStudentsRowCount); initial(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -