📄 classmagdialog.java
字号:
PrecisionRadioButton.setSelected(true);
}
{
FaintRadioButton = new JRadioButton();
QueryPanel.add(FaintRadioButton);
FaintRadioButton.setText("\u5e76\u4e14");
FaintRadioButton.setBounds(91, 112, 56, 21);
QuerybuttonGroup.add(FaintRadioButton);
}
{
OrRadioButton = new JRadioButton();
QueryPanel.add(OrRadioButton);
OrRadioButton.setText("\u6216\u8005");
OrRadioButton.setBounds(168, 112, 56, 21);
QuerybuttonGroup.add(OrRadioButton);
}
{
ComboBoxModel QueryComboBoxModel = new DefaultComboBoxModel(
combList);
QueryComboBox = new JComboBox();
QueryPanel.add(QueryComboBox);
QueryComboBox.setModel(QueryComboBoxModel);
QueryComboBox.setBounds(21, 14, 91, 28);
QueryComboBox
.addActionListener(new ActionListener() {
public void actionPerformed(
ActionEvent evt) {
QueryComboBoxActionPerformed(evt);
}
});
}
{
ClassQueryTextField = new JTextField();
QueryPanel.add(ClassQueryTextField);
ClassQueryTextField
.setText("\u8bf7\u8f93\u5165\u67e5\u8be2\u4fe1\u606f");
ClassQueryTextField.setBounds(238, 14, 119, 28);
ClassQueryTextField.setSize(105, 28);
}
{
ClassQueryButton = new JButton();
QueryPanel.add(ClassQueryButton);
ClassQueryButton.setText("\u67e5\u8be2");
ClassQueryButton.setBounds(21, 336, 70, 21);
ClassQueryButton
.addActionListener(new ActionListener() {
public void actionPerformed(
ActionEvent evt) {
ClassQueryButtonActionPerformed(evt);
}
});
}
{
ComboBoxModel CompareComboBoxModel = new DefaultComboBoxModel(
comCompareList);
CompareComboBox = new JComboBox();
QueryPanel.add(CompareComboBox);
CompareComboBox.setModel(CompareComboBoxModel);
CompareComboBox.setBounds(126, 14, 91, 28);
}
{
SelectRageCheckBox1 = new JCheckBox();
QueryPanel.add(SelectRageCheckBox1);
SelectRageCheckBox1
.setText("\u662f\u5426\u9009\u62e9\u8303\u56f4");
SelectRageCheckBox1.setBounds(126, 49, 112, 21);
SelectRageCheckBox1
.addActionListener(new ActionListener() {
public void actionPerformed(
ActionEvent evt) {
SelectRageCheckBox1ActionPerformed(evt);
}
});
}
{
FirstTextField = new JTextField();
QueryPanel.add(FirstTextField);
FirstTextField.setBounds(126, 77, 63, 28);
FirstTextField.setSize(91, 28);
}
{
RageLabel = new JLabel();
QueryPanel.add(RageLabel);
RageLabel.setText("\u81f3");
RageLabel.setBounds(224, 77, 21, 28);
}
{
EndTextField = new JTextField();
QueryPanel.add(EndTextField);
EndTextField.setBounds(245, 77, 91, 28);
}
{
ListModel QueryConditionList1Model = new DefaultComboBoxModel(
column1);
QueryConditionList1 = new JList();
QueryPanel.add(QueryConditionList1);
QueryConditionList1
.setModel(QueryConditionList1Model);
QueryConditionList1
.setBounds(21, 161, 259, 154);
}
{
ClearButton = new JButton();
QueryPanel.add(ClearButton);
ClearButton.setText("\u6e05\u9664");
ClearButton.setBounds(112, 336, 70, 21);
ClearButton
.addActionListener(new ActionListener() {
public void actionPerformed(
ActionEvent evt) {
ClearButtonActionPerformed(evt);
}
});
}
{
AddButton = new JButton();
QueryPanel.add(AddButton);
AddButton.setText("\u589e\u52a0");
AddButton.setBounds(203, 336, 70, 21);
AddButton
.addActionListener(new ActionListener() {
public void actionPerformed(
ActionEvent evt) {
AddButtonActionPerformed(evt);
}
});
}
}
{
DataViewPanel1 = new JPanel();
ClassMagTabbedPane.addTab("班级显示", null,
DataViewPanel1, null);
DataViewPanel1.setSize(569, 373);
{
ClassQueryScrollPane = new JScrollPane();
DataViewPanel1.add(ClassQueryScrollPane);
ClassQueryScrollPane.setBounds(63, 294, 420,
133);
ClassQueryScrollPane
.setPreferredSize(new java.awt.Dimension(
522, 318));
{
ClassQueryTableModel = new DefaultTableModel(
row, column);
ClassQueryTable = new JTable();
BorderLayout ClassQueryTableLayout = new BorderLayout();
ClassQueryTable
.setLayout(ClassQueryTableLayout);
ClassQueryScrollPane
.setViewportView(ClassQueryTable);
ClassQueryTable
.setModel(ClassQueryTableModel);
//设置学生信息表每个单元格的高度
ClassQueryTable.setRowHeight(24);
ClassQueryTable.setBounds(14, 231, 63, 28);
ClassQueryTable.setPreferredSize(new java.awt.Dimension(504, 3025));
ClassQueryTable.getTableHeader().setPreferredSize(new java.awt.Dimension(504, 21));
ClassQueryTable
.addMouseListener(new MouseAdapter() {
public void mouseClicked(
MouseEvent evt) {
ClassQueryTableMouseClicked(evt);
}
});
}
}
}
}
}
}
setSize(900, 475);
} catch (Exception e) {
e.printStackTrace();
}
}
private void ModifyButtonActionPerformed(ActionEvent evt) {
// 修改班级信息
// 定义boolean型变量,是否成功保存
boolean bisSaved = false;
// 定义鼠标点击行
int nrow = 0;
// 定义Course对象
Class newclass = new Class();
// 获取鼠标点击行
nrow = this.ClassQueryTable.getSelectedRow();
//保存用户输入信息,并返回更新是否成功,同时获得Class对象值
bisSaved = this.updateUserInput(newclass);
//如果用户保存成功
if (bisSaved) {
JOptionPane.showMessageDialog(this, "成功修改!");
// 更新用户界面数据
this.ClassQueryTableModel.setValueAt(newclass.getClassName(),
nrow, 1);
this.ClassQueryTableModel.setValueAt(String.valueOf(newclass.getTeacherId()),
nrow,2);
this.ClassQueryTableModel.setValueAt(newclass.getTeacherName(),
nrow, 3);
this.ClassQueryTableModel.setValueAt(String.valueOf(newclass.getMajorId()),
nrow, 4);
this.ClassQueryTableModel.setValueAt(newclass.getMajorName(),
nrow, 5);
this.ClassQueryTableModel.setValueAt(String.valueOf(newclass.getStuNum()),
nrow, 6);
this.ClassQueryTableModel.setValueAt(String.valueOf(newclass.getFlagYear()),
nrow, 7);
// 新增、修改、删除可用、保存不可用
this.NewButton.setEnabled(true);
this.ModifyButton.setEnabled(true);
this.DeleteButton.setEnabled(true);
this.SaveButton.setEnabled(false);
// 学科号自动增长,显示学科号,文本框设为不可用
this.ClassIdTextField.setEnabled(false);
} else {
JOptionPane.showMessageDialog(this, "修改失败!请重试!");
}
}
/**
* 初始化对话框,显示班级编号,班级名,班级人数
* 显示为学生分配班级对话框
* @param evt
*/
private void DistriStuButtonActionPerformed(ActionEvent evt) {
//为学生分配班级
//boolean型变量 初始化表格是否成功,初始化为false
boolean bisRight = false ;
//建立班级对象
Class newclass = new Class();
//获取鼠标点击数据,为类变量newclass赋值
newclass = this.getMouseClickData(newclass);
if(newclass.getClassName().equals(null)
|| newclass.getTeacherId() > 1000
|| newclass.getStuNum() > 100
|| newclass.getMajorId() >1000
|| !String.valueOf(newclass.getFlagYear()).matches(REG_DIGFlagYear)){
//如果用户没选择一行数据
bisRight = false;
//提示错误信息
JOptionPane.showMessageDialog(this, "您没有选择数据!在删除前请先选择一个班级!");
}else{
bisRight = true;
}
if(bisRight){
StuMatchClassDialog stuMatchClassDialog = new StuMatchClassDialog(null);
//向StuMatchClassDialog中添加数据
stuMatchClassDialog.classIdViewLabel.setText(
String.valueOf(newclass.getClassId()));
stuMatchClassDialog.classNameViewLabel.setText(
newclass.getClassName());
stuMatchClassDialog.stuNumViewLabel.setText(
String.valueOf(newclass.getStuNum()));
//初始化已选学生表格
bisRight = this.initSelectedStudentTable(stuMatchClassDialog);
stuMatchClassDialog.setModal(true);
stuMatchClassDialog.setVisible(true);
}
}
private void ExitButtonActionPerformed(ActionEvent evt) {
// 退出
this.dispose();
}
private void QueryComboBoxActionPerformed(ActionEvent evt) {
// 根据用户输入字段更改匹配符
// 定义String型变量, strTemp,存储用户选择的字段
String strUserSelect = "";
// 获取用户选择字段
strUserSelect = this.QueryComboBox.getSelectedItem().toString();
if (strUserSelect.equals("班级名") || strUserSelect.equals("班主任名")) {
this.CompareComboBox.removeAllItems();
this.CompareComboBox.addItem("匹配");
this.CompareComboBox.addItem("=");
}
if (strUserSelect.equals("班级号") || strUserSelect.equals("学生人数")
|| strUserSelect.equals("界别")) {
this.CompareComboBox.removeAllItems();
this.CompareComboBox.addItem(">");
this.CompareComboBox.addItem("<");
this.CompareComboBox.addItem("=");
}
}
private void SelectRageCheckBox1ActionPerformed(ActionEvent evt) {
// 用户是否选择范围
if (SelectRageCheckBox1.isSelected()) {
// 查询字段文本框不可用,清空,选择范围文本框可用
this.ClassQueryTextField.setEnabled(false);
this.FirstTextField.setEnabled(true);
this.EndTextField.setEnabled(true);
this.ClassQueryTextField.setText("");
} else {
// 选择范围文本框不可用,清空,查询字段文本框可用
this.ClassQueryTextField.setEnabled(true);
this.FirstTextField.setEnabled(false);
this.EndTextField.setEnabled(false);
this.FirstTextField.setText("");
this.EndTextField.setText("");
}
}
private void ClassQueryButtonActionPerformed(ActionEvent evt) {
// 班级查询
// 建立一个JDBC对象
JdbcConnct jdbcConnection = new JdbcConnct();
// 定义Vector变量,存储从数据库查询来的信息
Vector vecData = new Vector();
// 定义SQL组合子句
String strSQL = "select * from teach_clas_maj_view ";
String strSQL1 = " where ";
String strTemp = " order by ClassId ASC";
// 组合SQL语句
if (this.vecSQL.isEmpty()) {
strSQL += strTemp;
} else {
for (int i = 0; i < this.vecSQL.size(); i++) {
strSQL1 += this.vecSQL.get(i).toString();
}
strSQL += strSQL1 + strTemp;
}
// 刷新table中数据
ClassQueryTableModel = new DefaultTableModel(row, column);
this.ClassQueryTable.setModel(ClassQueryTableModel);
ClassQueryTable.getTableHeader().setBounds(0, 0, 469, -273);
// this.CourseQueryTable.setRowMargin(20);
// 获得数据
try {
vecData = jdbcConnection.getData(strSQL);
} catch (SQLException e) {
e.printStackTrace();
}
// 依次为各行插入数据
if (vecData.size() > 0) {
for (int i = 0; i < vecData.size(); i++) {
ClassQueryTableModel.addRow((String[]) vecData.get(i));
}
// 显示查询信息
this.ClassMagTabbedPane.setSelectedComponent(this.DataViewPanel1);
} else {
JOptionPane.showMessageDialog(this, "您查询的记录在数据库中不存在!请换一个查询条件.");
}
}
private void ClearButtonActionPerformed(ActionEvent evt) {
// 用户查询条件数量置为1
ncount = 1;
// 清空Vector变量vecSQL vecListView清空List控件中查询条件
this.vecSQL.clear();
this.vecListView.clear();
this.QueryConditionList1.setListData(vecListView);
// 清除按钮不可用
this.ClearButton.setEnabled(false);
}
private void AddButtonActionPerformed(ActionEvent evt) {
// 添加查询条件
// 定义SQL语句
String strSQL = "";
// 定义boolean型变量 isRight 用户操作是否正确,初始化false
boolean bisRight = false;
// 第一次必须选择”无“条件选项
if (!this.PrecisionRadioButton.isSelected() && ncount == 1) {
bisRight = false;
JOptionPane.showMessageDialog(this, "选择多条件查询时’无’选项须在第一次操作时选择,\n第一次"
+ "操作后请选择’或者’、‘并且’选项!");
} else if (this.PrecisionRadioButton.isSelected() && ncount > 1) {
// 第一次以后不能选择”无“条件选项
bisRight = false;
JOptionPane.showMessageDialog(this, "’无’选项须在第一次操作时选择,\n"
+ "第一次操作后请选择’或者’、‘并且’选项!");
} else {
bisRight = true;
// 成功则用户查询的条件数量加一
ncount++;
}
if (bisRight) {
// 获得用户选择,并转化为SQL语句
strSQL = this.getUserSelect();
// 向Vector变量vecSQL中添加变量
this.vecSQL.add(strSQL);
// 清空按钮可用,范围为本框不可用,查询字段文本框置为空
this.ClearButton.setEnabled(true);
this.FirstTextField.setEnabled(false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -