?? scoreuniversquerydialog.java
字號:
jScrollPane1
.setViewportView(ClassQueryList);
ClassQueryList
.setModel(ClassQueryListModel);
ClassQueryList
.setPreferredSize(new java.awt.Dimension(
185,
284));
ClassQueryList.setBounds(273, 98, 189, 168);
}
}
{
classQueryButton = new JButton();
classQueryPanel.add(classQueryButton);
classQueryButton.setText("\u67e5\u8be2");
classQueryButton.setBounds(28, 308, 63, 21);
classQueryButton
.addActionListener(new ActionListener() {
public void actionPerformed(
ActionEvent evt) {
classQueryButtonActionPerformed(evt);
}
});
}
{
clearButton = new JButton();
classQueryPanel.add(clearButton);
clearButton.setText("\u6e05\u7a7a");
clearButton.setBounds(105, 308, 63, 21);
clearButton
.addActionListener(new ActionListener() {
public void actionPerformed(
ActionEvent evt) {
clearButtonActionPerformed(evt);
}
});
}
{
addButton = new JButton();
classQueryPanel.add(addButton);
addButton.setText("\u589e\u52a0");
addButton.setBounds(182, 308, 63, 21);
addButton
.addActionListener(new ActionListener() {
public void actionPerformed(
ActionEvent evt) {
addButtonActionPerformed(evt);
}
});
}
}
{
queryResultPanel = new JPanel();
ScorQueryTabbedPane.addTab("查詢結果", null,
queryResultPanel, null);
queryResultPanel.setLayout(null);
queryResultPanel.setFont(new java.awt.Font("Dialog",0,12));
{
ClassQueryScrollPane1 = new JScrollPane();
queryResultPanel.add(ClassQueryScrollPane1);
ClassQueryScrollPane1.setBounds(21, 21, 504,
308);
{
ClassQueryTableModel = new DefaultTableModel(
row, combListStu);
ClassQueryTable = new JTable();
ClassQueryScrollPane1
.setViewportView(ClassQueryTable);
ClassQueryTable
.setModel(ClassQueryTableModel);
ClassQueryTable.setRowHeight(24);
ClassQueryTable.setPreferredSize(new java.awt.Dimension(483, 1771));
ClassQueryTable
.setBounds(49, 161, 483, 350);
ClassQueryTable.getTableHeader().setBounds(
0, 0, 504, 14);
ClassQueryTable
.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
ClassQueryTableMouseClicked(evt);
}
});
}
}
}
{
dataViewPanel = new JPanel();
ScorQueryTabbedPane.addTab("數據顯示", null,
dataViewPanel, null);
dataViewPanel.setFont(new java.awt.Font("Dialog",0,12));
dataViewPanel.setLayout(null);
dataViewPanel
.setPreferredSize(new java.awt.Dimension(
539, 357));
{
stuScroeScrollPane = new JScrollPane();
dataViewPanel.add(stuScroeScrollPane);
stuScroeScrollPane.setBounds(21, 21, 504, 308);
{
stuScoreTableModel = new DefaultTableModel(
row, columnStudent);
stuScoreTable = new JTable();
stuScroeScrollPane
.setViewportView(stuScoreTable);
stuScoreTable.setModel(stuScoreTableModel);
stuScoreTable.setRowHeight(24);
stuScoreTable.setPreferredSize(new java.awt.Dimension(483, 378));
stuScoreTable.setBounds(42, 21, 448, 210);
stuScoreTable.getTableHeader().setBounds(0, 0, 483, 21);
}
}
}
}
{
String[] year = new String[20];// 能查詢的年份為當前年份的前50年,后30年 for (int i = nowYear - 10, j = 0; i < nowYear + 10
&& j < 20; i++, j++) {
year[j] = i + "";
}
SpinnerListModel yearSelectSpinnerModel = new SpinnerListModel(year);
//設置為當前年 yearSelectSpinnerModel.setValue(this.nowYear + "");
yearSelectSpinner = new JSpinner();
ScoreQueryPanel.add(yearSelectSpinner);
yearSelectSpinner.setModel(yearSelectSpinnerModel);
yearSelectSpinner.setBounds(616, 98, 77, 28);
yearSelectSpinner
.addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent evt) {
yearSelectSpinnerMouseWheelMoved(evt);
}
});
}
{
ComboBoxModel conditionComboBoxModel = new DefaultComboBoxModel(
columnScoreQuery);
conditionComboBox = new JComboBox();
ScoreQueryPanel.add(conditionComboBox);
conditionComboBox.setModel(conditionComboBoxModel);
conditionComboBox.setBounds(707, 98, 70, 28);
}
{
studentQueryButton = new JButton();
ScoreQueryPanel.add(studentQueryButton);
studentQueryButton.setText("\u6210\u7ee9\u67e5\u8be2");
studentQueryButton.setBounds(791, 98, 91, 28);
studentQueryButton
.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
studentQueryButtonActionPerformed(evt);
}
});
}
{
stuQueryViewLabel = new JLabel();
ScoreQueryPanel.add(stuQueryViewLabel);
stuQueryViewLabel
.setText("\u5b66\u751f\u6210\u7ee9\u67e5\u8be2");
stuQueryViewLabel.setBounds(616, 21, 259, 28);
stuQueryViewLabel
.setFont(new java.awt.Font("宋體", 0, 14));
stuQueryViewLabel.setForeground(new java.awt.Color(0,
0, 255));
}
{
fullQueryRadioButton = new JRadioButton();
ScoreQueryPanel.add(fullQueryRadioButton);
fullQueryRadioButton
.setText("\u6240\u6709\u6210\u7ee9");
fullQueryRadioButton.setBounds(616, 63, 84, 21);
scoreQuerybuttonGroup.add(fullQueryRadioButton);
fullQueryRadioButton.setSelected(true);
fullQueryRadioButton
.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
fullQueryRadioButtonActionPerformed(evt);
}
});
}
{
commonRadioButton = new JRadioButton();
ScoreQueryPanel.add(commonRadioButton);
commonRadioButton.setText("\u5e73\u65f6\u6210\u7ee9");
commonRadioButton.setBounds(714, 63, 84, 21);
scoreQuerybuttonGroup.add(commonRadioButton);
commonRadioButton
.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
commonRadioButtonActionPerformed(evt);
}
});
}
{
classIdLabel = new JLabel();
ScoreQueryPanel.add(classIdLabel);
classIdLabel.setText("\u73ed\u7ea7\u7f16\u53f7");
classIdLabel.setBounds(616, 196, 56, 28);
}
{
classIdViewLabel = new JLabel();
ScoreQueryPanel.add(classIdViewLabel);
classIdViewLabel.setText("1");
classIdViewLabel.setBounds(672, 196, 35, 28);
classIdViewLabel.setForeground(new java.awt.Color(0, 0,
255));
}
{
classNameLabel = new JLabel();
ScoreQueryPanel.add(classNameLabel);
classNameLabel.setText("\u73ed\u7ea7\u540d");
classNameLabel.setBounds(707, 196, 56, 28);
}
{
classNameViewLabel = new JLabel();
ScoreQueryPanel.add(classNameViewLabel);
classNameViewLabel.setText("\u73ed\u7ea7\u540d");
classNameViewLabel.setBounds(763, 196, 126, 28);
classNameViewLabel.setForeground(new java.awt.Color(0, 0, 255));
}
{
fullSubjectQueryRadioButton = new JRadioButton();
ScoreQueryPanel.add(fullSubjectQueryRadioButton);
fullSubjectQueryRadioButton.setText("\u6240\u6709\u79d1\u76ee\u67e5\u8be2");
fullSubjectQueryRadioButton.setSelected(true);
fullSubjectQueryRadioButton.setBounds(616, 231, 105, 21);
classQuerybuttonGroup.add(fullSubjectQueryRadioButton);
fullSubjectQueryRadioButton
.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
fullSubjectQueryRadioButtonActionPerformed(evt);
}
});
}
{
subjectQueryRadioButton = new JRadioButton();
ScoreQueryPanel.add(subjectQueryRadioButton);
subjectQueryRadioButton.setText("\u5206\u79d1\u76ee\u67e5\u8be2");
subjectQueryRadioButton.setBounds(735, 231, 105, 21);
classQuerybuttonGroup.add(subjectQueryRadioButton);
subjectQueryRadioButton
.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
subjectQueryRadioButtonActionPerformed(evt);
}
});
}
{
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
combListSubject);
subjectConditionComboBox = new JComboBox();
ScoreQueryPanel.add(subjectConditionComboBox);
subjectConditionComboBox.setModel(jComboBox1Model);
subjectConditionComboBox.setBounds(616, 266, 84, 28);
}
{
classScoreQueryButton = new JButton();
ScoreQueryPanel.add(classScoreQueryButton);
classScoreQueryButton.setText("\u6210\u7ee9\u67e5\u8be2");
classScoreQueryButton.setBounds(791, 266, 91, 28);
classScoreQueryButton
.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
classScoreQueryButtonActionPerformed(evt);
}
});
}
{
VSeparator = new JSeparator();
ScoreQueryPanel.add(VSeparator);
VSeparator.setBounds(588, 0, 7, 448);
VSeparator.setOrientation(SwingConstants.VERTICAL);
}
{
HorSeparator1 = new JSeparator();
ScoreQueryPanel.add(HorSeparator1);
HorSeparator1.setBounds(588, 308, 308, 21);
}
{
exitButton = new JButton();
ScoreQueryPanel.add(exitButton);
exitButton.setText("\u9000\u51fa");
exitButton.setBounds(791, 343, 70, 28);
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
exitButtonActionPerformed(evt);
}
});
}
}
}
setSize(900, 475);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 學生查詢清空查詢條件 *
* @param evt
*/
private void clearStuQueryButtonActionPerformed(ActionEvent evt) {
ncount = 1;
// 清空Vector變量vecSQL vecListView清空List控件中查詢條件 this.vecSQL.clear();
this.vecListView.clear();
this.studentQueryList1.setListData(vecListView);
// 清除按鈕不可用 this.clearStuQueryButton.setEnabled(false);
}
/** 班級查詢添加查詢條件 *
* @param evt
*/
private void addButtonActionPerformed(ActionEvent evt) {
String strSQL = "";
// 定義boolean型變量 isRight 用戶操作是否正確,初始化false
boolean bisRight = false;
// 第一次必須選擇”無“條件選項 if (!this.nullRadioButton.isSelected() && ncountClass == 1) {
bisRight = false;
JOptionPane.showMessageDialog(this, "選擇多條件查詢時’無’選項須在第一次操作時選擇,\n第一次"
+ "操作后請不要再選擇’無’選項!");
} else if (this.nullRadioButton.isSelected() && ncountClass > 1) {
// 第一次以后不能選擇”無“條件選項 bisRight = false;
JOptionPane.showMessageDialog(this, "’無’選項須在第一次操作時選擇,\n"
+ "第一次操作后請不要再選擇’無’選項!");
} else {
bisRight = true;
// 用戶查詢的條件數量加一 ncountClass++;
}
if (bisRight) {
// 獲得用戶選擇,并轉化為SQL語句 strSQL = this.getUserSelectClass();
System.out.println("\t" + strSQL);
// 向Vector變量vecSQLClass中添加變量 this.vecSQLClass.add(strSQL);
// 清空按鈕可用,范圍為本框不可用,查詢字段文本框置為空 this.clearButton.setEnabled(true);
this.commentTextField.setText("");
}
}
/**
* 添加學生查詢條件 *
* @param evt
*/
private void addStuQueryButtonActionPerformed(ActionEvent evt) {
// 定義SQL語句 String strSQL = "";
// 定義boolean型變量 isRight 用戶操作是否正確,初始化false
boolean bisRight = false;
// 第一次必須選擇”無“條件選項 if (!this.nullRadioButton1.isSelected() && ncount == 1) {
bisRight = false;
JOptionPane.showMessageDialog(this, "選擇多條件查詢時’無’選項須在第一次操作時選擇,\n第一次"
+ "操作后請不要再選擇’無’選項!");
} else if (this.nullRadioButton1.isSelected() && ncount > 1) {
// 第一次以后不能選擇”無“條件選項 bisRight = false;
JOptionPane.showMessageDialog(this, "’無’選項須在第一次操作時選擇,\n"
+ "第一次操作后請不要再選擇’無’選項!");
} else {
bisRight = true;
// 用戶查詢的條件數量加一 ncount++;
}
if (bisRight) {
// 獲得用戶選擇,并轉化為SQL語句 strSQL = this.getUserSelect();
System.out.println("\t" + strSQL);
// 向Vector變量vecSQL中添加變量 this.vecSQL.add(strSQL);
// 清空按鈕可用,范圍為本框不可用,查詢字段文本框置為空 this.clearStuQueryButton.setEnabled(true);
this.userInputTextField1.setText("");
}
}
/**
* 根據班級查詢條件匹配比較符 *
* @param evt
*/
private void ClassQueryComboBoxActionPerformed(ActionEvent evt) {
String strUserSelectclass = "";
// 獲取用戶選擇字段 strUserSelectclass = this.ClassQueryComboBox.getSelectedItem()
.toString();
if (strUserSelectclass.equals("班級名")) {
this.classQueryConditionComboBox.removeAllItems();
this.classQueryConditionComboBox.addItem("匹配");
this.classQueryConditionComboBox.addItem("=");
}
if (strUserSelectclass.equals("班級號") || strUserSelectclass.equals("屆別")) {
this.classQueryConditionComboBox.removeAllItems();
this.classQueryConditionComboBox.addItem(">");
this.classQueryConditionComboBox.addItem("<");
this.classQueryConditionComboBox.addItem("=");
}
}
/**
* 班級查詢,顯示班級信息 *
* @param evt
* 鼠標響應事件 */
private void classQueryButtonActionPerformed(ActionEvent evt) {
// 查詢班級 // 建立一個JDBC對象 JdbcConnct jdbcConnection = new JdbcConnct();
// 定義Vector變量,存儲從數據庫查詢來的信息 Vector vecData = new Vector();
// 定義SQL語句組合項 String strSQL = "select classid,classname,flagyear from zlb.classes ";
String strSQL1 = " where ";
String strTemp = " order by classid ASC";
// 組合SQL語句 if (this.vecSQLClass.isEmpty()) {
strSQL += strTemp;
} else {
for (int i = 0; i < this.vecSQLClass.size(); i++) {
strSQL1 += this.vecSQLClass.get(i).toString();
}
strSQL += strSQL1 + strTemp;
}
// 刷新table中數據 DefaultTableModel StuQueryTableModel = new DefaultTableModel(row,
combListClass);
this.ClassQueryTable.setModel(StuQueryTableModel);
// 獲得數據 try {
vecData = jdbcConnection.getData(strSQL);
} catch (SQLException e) {
e.printStackTrace();
}
// 依次為各行插入數據 if (vecData.size() > 0) {
for (int i = 0; i < vecData.size(); i++) {
StuQueryTableModel.addRow((String[]) vecData.get(i));
}
// 顯示查詢數據 this.ScorQueryTabbedPane
.setSelectedComponent(this.queryResultPanel);
//用戶點擊表格次數置為1
nclickNum = 1;
} else {
JOptionPane.showMessageDialog(this, "您查詢的記錄在數據庫中不存在!請換一個查詢條件.");
}
}
/**
* 清除班級查詢條件 *
* @param evt
*/
private void clearButtonActionPerformed(ActionEvent evt) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -