📄 cstudeldlg.java
字号:
package ui;
import main.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import value.*;
/**
*
* <p>标题:CStuDelDlg</p>
* <p>描述:删除学生信息窗体类</p>
* <p>作者@author:陈新</p>
* <p>公司:com.thinkbank.04024</p>
* <p>版权:Copyrigth (c) 2005 </p>
* <p>编写日期:2005-10-10</p>
* <p>版本号@version 1.0.06.01
*/
public class CStuDelDlg extends javax.swing.JDialog implements ActionListener{
private JButton jBtnCancel;//取消
private JButton jBtnSubmit;//确定
private JButton jStuSechBtn;//查询
private JTextField jStuIDTxt;//查询的学生号
private JLabel jStuSex;//返回的性别
private JLabel jStuClsID;//返回的班级号
private JLabel jStuName;//返回的姓名
private JLabel jStuId;//返回的学生号
//只显示,不使用的控件
private JLabel jStuIDLbl;
private JLabel jStuNamelbl;
private JLabel jStuSexlbl;
private JLabel jStuClsidlbl;
private JLabel jLabel1;
public CStuDelDlg(JFrame frame) {
super(frame);
initGUI();
}
/**
*
* <p>描述:窗体初始化方法</p>
*
*
*/
private void initGUI() {
try {
this.setTitle("删除学员信息");
this.setResizable(false);
this.getContentPane().setLayout(null);
{
jLabel1 = new JLabel();
this.getContentPane().add(jLabel1);
jLabel1.setText("请输入要删除学员的学号");
jLabel1.setBounds(20, 17, 154, 22);
}
{
jStuIDTxt = new JTextField();
this.getContentPane().add(jStuIDTxt);
jStuIDTxt.setText("");
jStuIDTxt.setBounds(182, 17, 83, 22);
}
{
jStuSechBtn = new JButton();
this.getContentPane().add(jStuSechBtn);
jStuSechBtn.setText("查找");
jStuSechBtn.setBounds(284, 18, 84, 23);
jStuSechBtn.addActionListener(this);
}
{
jStuIDLbl = new JLabel();
this.getContentPane().add(jStuIDLbl);
jStuIDLbl.setText("学员学号");
jStuIDLbl.setLayout(null);
jStuIDLbl.setBounds(86, 61, 85, 25);
}
{
jStuId = new JLabel();
this.getContentPane().add(jStuId);
jStuId.setText("");
jStuId.setLayout(null);
jStuId.setBounds(180, 61, 91, 23);
jStuId.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
}
{
jStuNamelbl = new JLabel();
this.getContentPane().add(jStuNamelbl);
jStuNamelbl.setText("学员姓名");
jStuNamelbl.setLayout(null);
jStuNamelbl.setBounds(85, 91, 85, 25);
}
{
jStuClsidlbl = new JLabel();
this.getContentPane().add(jStuClsidlbl);
jStuClsidlbl.setText("所在班级");
jStuClsidlbl.setLayout(null);
jStuClsidlbl.setBounds(84, 121, 85, 25);
}
{
jStuSexlbl = new JLabel();
this.getContentPane().add(jStuSexlbl);
jStuSexlbl.setText("学员性别");
jStuSexlbl.setLayout(null);
jStuSexlbl.setBounds(85, 151, 85, 25);
}
{
jBtnSubmit = new JButton();
this.getContentPane().add(jBtnSubmit);
jBtnSubmit.setText("确定");
jBtnSubmit.setBounds(108, 196, 60, 30);
jBtnSubmit.addActionListener(this);
}
{
jBtnCancel = new JButton();
this.getContentPane().add(jBtnCancel);
jBtnCancel.setText("取消");
jBtnCancel.setBounds(187, 196, 60, 30);
jBtnCancel.addActionListener(this);
}
{
jStuName = new JLabel();
this.getContentPane().add(jStuName);
jStuName.setText("");
jStuName.setLayout(null);
jStuName.setBounds(180, 91, 91, 23);
jStuName.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
}
{
jStuClsID = new JLabel();
this.getContentPane().add(jStuClsID);
jStuClsID.setText("");
jStuClsID.setLayout(null);
jStuClsID.setBounds(180,121, 91, 23);
jStuClsID.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
}
{
jStuSex = new JLabel();
this.getContentPane().add(jStuSex);
jStuSex.setText("");
jStuSex.setLayout(null);
jStuSex.setBounds(180, 151, 91, 23);
jStuSex.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
}
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* <p>描述:实现监听器类的方法</p>
*/
public void actionPerformed(ActionEvent evt){
Object source = evt.getSource();
if(source == jBtnCancel){
this.setVisible(false);
}
else if(source == jStuSechBtn){
if(jStuIDTxt.getText().equals("")){
JOptionPane.showConfirmDialog(this,"请输入学生号","提示",
JOptionPane.CLOSED_OPTION,
JOptionPane.WARNING_MESSAGE);
}
else {
CStuDAO stuDAO = new CStuDAO();
// ArrayList stuList = new ArrayList();
ArrayList stuList = null;
String sql = "select * from T_student where cStuId='"
+ jStuIDTxt.getText() + "'";
stuList = stuDAO.executeQuery(sql);
if(stuList!=null){
CStudents stu = (CStudents)stuList.get(0);
jStuId.setText(stu.getStrStuId());
jStuName.setText(stu.getStrStuName());
jStuSex.setText(stu.getStrSex());
jStuClsID.setText(stu.getStrClsID());
}
else if(stuList == null){
JOptionPane.showConfirmDialog(this,"不存在该学生号,请重新输入!"
,"提示",
JOptionPane.CLOSED_OPTION,
JOptionPane.WARNING_MESSAGE);
}
}
}
else if(source == jBtnSubmit){
if(jStuId.getText().equals("")){
JOptionPane.showConfirmDialog(this,"请先查找学生信息!","提示",
JOptionPane.CLOSED_OPTION,
JOptionPane.WARNING_MESSAGE);
}
else{
CStuDAO stuDAO = new CStuDAO();
String sql = "delete from T_student where cStuId='"
+ jStuId.getText() + "'";
int i = stuDAO.executeUpdate(sql);
if(i==1){
JOptionPane.showConfirmDialog(this,"删除成功!","提示",
JOptionPane.CLOSED_OPTION,
JOptionPane.WARNING_MESSAGE);
jStuIDTxt.setText("");
jStuId.setText("");
jStuSex.setText("");
jStuClsID.setText("");
jStuName.setText("");
CMain.updateFrame();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -