本系统实现的以下功能
管理员功能:登录系统、题目的增删改查、用户的增删改查、试题的分数设置。
考生功能:登录系统、考生考试、查看成绩、修改密码。
JDK版本:1.8
数据库:Mysql8.0.13
package com.sjsq.view;
import java.awt.Insets;
import javax.swing.*;
import javax.swing.GroupLayout;
import javax.swing.LayoutStyle;
import com.sjsq.bean.*;
import com.sjsq.controller.AdminMainFrame;
import com.sjsq.dao.*;
/**
*
* @author Administrator
*
* @author shuijianshiqing
*
* @date 2021-01-17
*
*/
public class LoginFrame extends javax.swing.JFrame {
/** Creates new form MyLand2 */
public LoginFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
private void initComponents() {
jTextField3 = new javax.swing.JTextField();
jTextField1 = new javax.swing.JTextField();
jpanel = new MyJPanel();
choicejLabel = new javax.swing.JLabel();
userChoicejComboBox = new javax.swing.JComboBox();
choicejLabel1 = new javax.swing.JLabel();
UserNameTextField = new javax.swing.JTextField();
choicejLabel2 = new javax.swing.JLabel();
PassWordjTextField = new javax.swing.JPasswordField();
enterButton = new javax.swing.JButton();
enterButton.setMargin(new Insets(2, 2, 2, 2));
resButtonjButton = new javax.swing.JButton();
resButtonjButton.setMargin(new Insets(2, 2, 2, 2));
jTextField3.setText("jTextField3");
jTextField1.setText("jTextField1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
choicejLabel.setText("选择用户:");
userChoicejComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
"", "考生", "管理员" }));
setTitle("考试系统");
choicejLabel1.setText("用 户 名:");
UserNameTextField.setText("");
choicejLabel2.setText(" 密 码 :");
PassWordjTextField.setText("");
enterButton.setText("登录");
enterButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
enterButtonActionPerformed(evt);
}
});
resButtonjButton.setText("重置");
resButtonjButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jpanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jpanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
javax.swing.GroupLayout jpanelLayout = new javax.swing.GroupLayout(jpanel);
jpanelLayout.setHorizontalGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
.addGroup(jpanelLayout.createSequentialGroup().addGap(216, 216, 216).addGroup(jpanelLayout
.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jpanelLayout.createSequentialGroup()
.addComponent(choicejLabel, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(userChoicejComboBox, GroupLayout.PREFERRED_SIZE, 120,
GroupLayout.PREFERRED_SIZE))
.addGroup(jpanelLayout.createSequentialGroup()
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jpanelLayout.createSequentialGroup()
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(choicejLabel2, GroupLayout.PREFERRED_SIZE, 71,
GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(PassWordjTextField, GroupLayout.DEFAULT_SIZE, 120,
Short.MAX_VALUE))
.addGroup(jpanelLayout.createSequentialGroup()
.addComponent(choicejLabel1, GroupLayout.PREFERRED_SIZE, 71,
GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(UserNameTextField, GroupLayout.DEFAULT_SIZE, 120,
Short.MAX_VALUE)))))
.addGap(82, 82, 82))
.addGroup(jpanelLayout.createSequentialGroup().addContainerGap(256, Short.MAX_VALUE)
.addComponent(enterButton, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(resButtonjButton)
.addGap(123, 123, 123)));
jpanelLayout.setVerticalGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jpanelLayout.createSequentialGroup().addGap(85, 85, 85)
.addGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(choicejLabel).addComponent(userChoicejComboBox,
GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(choicejLabel1).addComponent(UserNameTextField, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(choicejLabel2).addComponent(PassWordjTextField,
GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(resButtonjButton, GroupLayout.PREFERRED_SIZE, 23,
GroupLayout.PREFERRED_SIZE)
.addComponent(enterButton, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE))
.addContainerGap(71, Short.MAX_VALUE)));
jpanel.setLayout(jpanelLayout);
pack();
}
private void enterButtonActionPerformed(java.awt.event.ActionEvent evt) {
if (userChoicejComboBox.getSelectedIndex() == 0) {
JOptionPane.showMessageDialog(this, "没有确定路径的'用户类型'", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (UserNameTextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "用户名不能为空", "密码不能为空", JOptionPane.WARNING_MESSAGE);
return;
}
if (PassWordjTextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "密码不能为空", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
MyFindUserDao findUser = new MyFindUserDao();
User user = new User();
user.setUserName(UserNameTextField.getText());
user.setPassWord(PassWordjTextField.getText());
User users = findUser.getUser(user);
if ((users.getUserType() == 1 && !(userChoicejComboBox.getSelectedItem().equals("管理员")))) {
JOptionPane.showMessageDialog(this, "登录系统身份不符", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if ((users.getUserType() == 0) && !(userChoicejComboBox.getSelectedItem().equals("考生"))) {
JOptionPane.showMessageDialog(this, "登录系统身份不符", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
// 考生
if ((users.getId() != 0) && (users.getUserType() == 0)) {
int id = users.getId();
java.io.File file = new java.io.File("save.txt");
try {
if (file.exists()) {
file.delete();
}
file.createNewFile();
java.io.FileOutputStream out = new java.io.FileOutputStream(file);
byte buy[] = ("" + id).getBytes();
out.write(buy);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
InsertUserDao insertUserDao = new InsertUserDao();
insertUserDao.setUserHaveIn(users);
StudentMainFrame studentExam = new StudentMainFrame();
studentExam.setVisible(true);
studentExam.setBounds(200, 200, 500, 400);
studentExam.setTitle("考试系统");
studentExam.setLocationRelativeTo(null);
this.dispose();
}
// 管理员
if ((users.getId() != 0) && (users.getUserType() == 1)) {
dispose();
AdminMainFrame controller = new AdminMainFrame();
controller.setVisible(true);
controller.setBounds(100, 100, 700, 500);
controller.setLocationRelativeTo(null);
} else if (users.getId() == 0) {
JOptionPane.showMessageDialog(this, "用户名或密码错误", "信息对话框", JOptionPane.WARNING_MESSAGE);
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
UserNameTextField.setText("");
PassWordjTextField.setText("");
}
// 主函数运行
public static void main(String[] args) {
LoginFrame myLand = new LoginFrame();
//myLand.setBounds(0, 0, 400, 300);
myLand.setVisible(true);
myLand.setLocationRelativeTo(null);
}
private javax.swing.JLabel choicejLabel;
private javax.swing.JLabel choicejLabel1;
private javax.swing.JLabel choicejLabel2;
private javax.swing.JButton enterButton;
private javax.swing.JButton resButtonjButton;
private javax.swing.JComboBox userChoicejComboBox;
private javax.swing.JPasswordField PassWordjTextField;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField UserNameTextField;
private javax.swing.JTextField jTextField3;
private MyJPanel jpanel;
}
/*
* ControllerFrame.java
*
* Created on 2008年8月7日, 下午2:41
*/
package com.sjsq.controller;
import java.io.File;
import java.security.UnresolvedPermission;
import java.util.ArrayList;
import javax.swing.GroupLayout;
import javax.swing.JOptionPane;
import javax.swing.LayoutStyle;
import javax.swing.table.DefaultTableModel;
import com.sjsq.bean.*;
import com.sjsq.dao.FindGrade;
/**
*
* @author Administrator
*/
public class AdminMainFrame extends javax.swing.JFrame {
// 主控制窗体
/** Creates new form ControllerFrame */
public AdminMainFrame() {
// 构造方法
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
// desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
// 初始化方法
jPanel1 = new javax.swing.JPanel();
messageLabel = new javax.swing.JLabel();
messageJchock = new javax.swing.JComboBox();
ifLabel = new javax.swing.JLabel();
nameTextField = new javax.swing.JTextField();
findButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
addquestion = new javax.swing.JButton();
addUserButton = new javax.swing.JButton();
closeButton = new javax.swing.JButton();
jSeparator1 = new javax.swing.JSeparator();
downmessage = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
superControll = new javax.swing.JMenu();
addMenu = new javax.swing.JMenu();
addradioItem = new javax.swing.JMenuItem();
addmoreItem = new javax.swing.JMenuItem();
addjubje = new javax.swing.JMenuItem();
updateMenu = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
userManager = new javax.swing.JMenuItem();
findGrade = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
messageLabel.setText("查询条件:");
messageJchock.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
"考生号", "考生姓名" }));
ifLabel.setText("查询值:");
nameTextField.setText("");
findButton.setText("查询");
findButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
findButtonActionPerformed(evt);
}
});
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] {
}, new String[] {
"考生编号", "考生姓名", "单选题得分", "多选题得分", "判断题得分", "总分", "考试时间" }
));
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
FindGrade findGradebean = new FindGrade();
java.util.List list = findGradebean.findGrade();// 把获取的所有学分用户放入list
setTitle("考试系统---管理员");
if (!list.isEmpty()) {
for (int j = 0; j < list.size(); j++) {
Grade grade = (Grade) list.get(j);
model.addRow(new Object[] {
// 添加所有学分用户
grade.getId(), ChDeal.toChinese(grade.getUserName()), grade.getRadioResult(),
grade.getFullResule(), grade.getEsitResult(), grade.getBatsisResult(),
ChDeal.toChinese(grade.getDate()) });
}
}
jScrollPane1.setViewportView(jTable1);
addquestion.setText("添加试题");
addquestion.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addquestionActionPerformed(evt);
}
});
addUserButton.setText("添加用户");
addUserButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addUserButtonActionPerformed(evt);
}
});
closeButton.setText("退出");
closeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closeButtonActionPerformed(evt);
}
});
//downmessage.setText("版权所有:吉林省明日科技有限公司。");
//jLabel1.setText(" 网 址 :www.mrbccd.com");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout
.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1, GroupLayout.DEFAULT_SIZE, 596, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addComponent(addUserButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(addquestion, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(closeButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
.addGap(12, 12, 12)
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, GroupLayout.Alignment.TRAILING,
GroupLayout.DEFAULT_SIZE, 498, Short.MAX_VALUE)
.addGroup(
jPanel1Layout.createSequentialGroup().addComponent(messageLabel)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED,
GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(messageJchock, GroupLayout.PREFERRED_SIZE,
92, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ifLabel)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nameTextField, GroupLayout.PREFERRED_SIZE,
137, GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(findButton, GroupLayout.PREFERRED_SIZE,
67, GroupLayout.PREFERRED_SIZE)
.addGap(31, 31, 31)))))
.addContainerGap())
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addGap(10, 10, 10).addComponent(
jLabel1, GroupLayout.PREFERRED_SIZE, 195, GroupLayout.PREFERRED_SIZE))
.addComponent(downmessage, GroupLayout.PREFERRED_SIZE, 287,
GroupLayout.PREFERRED_SIZE))
.addGap(135, 135, 135)))));
jPanel1Layout
.setVerticalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(ifLabel)
.addComponent(messageJchock, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(messageLabel)
.addComponent(nameTextField, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(findButton))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addGap(33, 33, 33)
.addComponent(addquestion).addGap(43, 43, 43)
.addComponent(addUserButton).addGap(42, 42, 42)
.addComponent(closeButton))
.addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 264,
GroupLayout.PREFERRED_SIZE))
.addGap(8, 8, 8)
.addComponent(jSeparator1, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(downmessage)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel1)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
jPanel1.setLayout(jPanel1Layout);
superControll.setText("题库管理");
addMenu.setText("增加考题");
addMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addMenuActionPerformed(evt);
}
});
addradioItem.setText("增加单选题");
addMenu.add(addradioItem);
addradioItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addradioItemActionPerformed(evt);
}
});
addmoreItem.setText("增加多选题");
addmoreItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addmoreItemActionPerformed(evt);
}
});
addMenu.add(addmoreItem);
addjubje.setText("增加判断题");
addjubje.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addjubjeActionPerformed(evt);
}
});
addMenu.add(addjubje);
superControll.add(addMenu);
updateMenu.setText("修改/删除考题");
updateMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
updateMenuActionPerformed(evt);
}
});
superControll.add(updateMenu);
jMenuBar1.add(superControll);
jMenu2.setText("系统管理");
userManager.setText("用户管理");
userManager.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
userManagerActionPerformed(evt);
}
});
jMenu2.add(userManager);
findGrade.setText("参数设置");
findGrade.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
findGradeActionPerformed(evt);
}
});
jMenu2.add(findGrade);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(jPanel1,
GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(jPanel1,
GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE));
getContentPane().setLayout(layout);
pack();
}
private void findButtonActionPerformed(java.awt.event.ActionEvent evt) {
boolean flag = false;// 没查询到为true;否则为false
// 首先判断用户是否输入查询值
if (nameTextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "请输入查询条件", "消息对话框", JOptionPane.WARNING_MESSAGE);
return; // 如果有没有输入查询值 返回
}
// 如果用户选择按“考生号”查询考分,系统将调用getGradeID()方法,并将查询结果显示在窗体中
if (messageJchock.getSelectedItem().toString().equals("考生号")) {
FindGrade findGrade = new FindGrade();
java.util.List<Grade> gradeList = findGrade.findGrade();
if (!gradeList.isEmpty()) {
for (int i = 0; i < gradeList.size(); i++) {
Grade grade = gradeList.get(i);
try {
if (grade.getId() != Integer.parseInt(nameTextField.getText())) {
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "必须输入数字!", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (grade.getId() == Integer.parseInt(nameTextField.getText())) {
Grade gradeId = findGrade.getGradeID(grade);
if (gradeId != null) {
((DefaultTableModel) jTable1.getModel()).setRowCount(0);
((DefaultTableModel) jTable1.getModel())
.addRow(new Object[] {
grade.getId(), ChDeal.toChinese(grade.getUserName()),
grade.getRadioResult(), grade.getFullResule(), grade.getEsitResult(),
grade.getBatsisResult(), ChDeal.toChinese(grade.getDate()) });
flag = false;
return;
}
} else {
flag = true;
}
}
if (flag) {
JOptionPane.showMessageDialog(this, "没有要查询的考生成绩!", "信息对话框", JOptionPane.WARNING_MESSAGE);
}
}
}
if (messageJchock.getSelectedItem().toString().equals("考生姓名")) {
FindGrade findGrade = new FindGrade();
Grade grade = new Grade();
grade.setUserName(nameTextField.getText());
Grade grage = findGrade.getGradeName(grade);
if ((grade.getUserName().equals(nameTextField.getText())) && (grage.getId() != 0)) {
((DefaultTableModel) jTable1.getModel()).setRowCount(0);
((DefaultTableModel) jTable1.getModel()).addRow(new Object[] {
grage.getId(), grage.getUserName(),
grage.getRadioResult(), grage.getFullResule(), grage.getEsitResult(), grage.getBatsisResult(),
ChDeal.toChinese(grage.getDate()) });
} else {
JOptionPane.showMessageDialog(this, "没有要查询的考生成绩!", "信息对话框", JOptionPane.WARNING_MESSAGE);
}
}
}
private void addquestionActionPerformed(java.awt.event.ActionEvent evt) {
AddExamFrame testFrame = new AddExamFrame();
testFrame.setVisible(true);
testFrame.setBounds(200, 150, 500, 500);
testFrame.setTitle("添加考题");
this.setVisible(false);
testFrame.setLocationRelativeTo(null);
}
private void updateMenuActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
UpdateFrame updateFrame = new UpdateFrame();
updateFrame.setVisible(true);
updateFrame.setBounds(100, 150, 630, 350);
updateFrame.setLocationRelativeTo(null);
}
private void addUserButtonActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
UserAddFrame addUser = new UserAddFrame();
addUser.setVisible(true);
addUser.setBounds(200, 200, 400, 300);
addUser.setTitle("添加用户对话框");
addUser.setLocationRelativeTo(null);
}
private void findGradeActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
UpdateExamParameter updateExam = new UpdateExamParameter();
updateExam.setTitle("参数设置");
updateExam.setVisible(true);
updateExam.setBounds(200, 150, 500, 330);
updateExam.setLocationRelativeTo(null);
}
private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {
int n = JOptionPane.showConfirmDialog(this, "确定要退出系统吗?", "确定对话框", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
System.exit(0);
}
if (n == JOptionPane.NO_OPTION) {
}
}
private void addMenuActionPerformed(java.awt.event.ActionEvent evt) {
}
private void addradioItemActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
AddRadioFrame addRadioFrame = new AddRadioFrame();
addRadioFrame.setTitle("添加单选题");
addRadioFrame.setVisible(true);
addRadioFrame.setBounds(200, 100, 400, 500);
addRadioFrame.setLocationRelativeTo(null);
}
private void addmoreItemActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
AddMoreFrame addMoreFrame = new AddMoreFrame();
addMoreFrame.setTitle("添加多选题");
addMoreFrame.setVisible(true);
addMoreFrame.setBounds(200, 100, 400, 500);
addMoreFrame.setLocationRelativeTo(null);
}
private void addjubjeActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
AddJudgeFrame addjudge = new AddJudgeFrame();
addjudge.setTitle("添加判断题");
addjudge.setVisible(true);
addjudge.setBounds(200, 150, 400, 350);
addjudge.setLocationRelativeTo(null);
}
private void userManagerActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
UserManagerFrame userAdd = new UserManagerFrame();
userAdd.setTitle("用户管理");
userAdd.setVisible(true);
userAdd.setBounds(200, 200, 425, 330);
userAdd.setLocationRelativeTo(null);
}
private javax.swing.JMenu addMenu;
private javax.swing.JButton addUserButton;
private javax.swing.JMenuItem addjubje;
private javax.swing.JMenuItem addmoreItem;
private javax.swing.JButton addquestion;
private javax.swing.JMenuItem addradioItem;
private javax.swing.JButton closeButton;
private javax.swing.JLabel downmessage;
private javax.swing.JButton findButton;
private javax.swing.JMenuItem findGrade;
private javax.swing.JLabel ifLabel;
private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField nameTextField;
private javax.swing.JComboBox messageJchock;
private javax.swing.JLabel messageLabel;
private javax.swing.JMenu superControll;
private javax.swing.JMenuItem updateMenu;
private javax.swing.JMenuItem userManager;
}
/*
* StudentExam.java
*
* Created on 2008年8月2日, 上午10:04
*/
package com.sjsq.view;
import java.util.List;
import javax.swing.JOptionPane;
import com.sjsq.bean.*;
import com.sjsq.dao.*;
import com.sjsq.student.ExamPage;
/**
*
* @author Administrator
*/
public class StudentMainFrame extends javax.swing.JFrame {
/** Creates new form StudentExam */
public StudentMainFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// // Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel = new MySudentExamJPanel();
jMenuBar1 = new javax.swing.JMenuBar();
FilejMenu = new javax.swing.JMenu();
openjMenuItem = new javax.swing.JMenuItem();
closeMenuItem = new javax.swing.JMenuItem();
watchjMenu = new javax.swing.JMenu();
sleanjMenuItem = new javax.swing.JMenuItem();
amendpassjMenuItem = new javax.swing.JMenuItem();
aboutjMenu = new javax.swing.JMenu();
aboutExamMenuItem = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
FilejMenu.setText("考试");
setTitle("考试系统---考生");
openjMenuItem.setText("开始考试");
openjMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
openjMenuItemActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanelLayout = new javax.swing.GroupLayout(jPanel);
jPanel.setLayout(jPanelLayout);
jPanelLayout.setHorizontalGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE));
FilejMenu.add(openjMenuItem);
closeMenuItem.setText("退出");
closeMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closeMenuItemActionPerformed(evt);
}
});
FilejMenu.add(closeMenuItem);
jMenuBar1.add(FilejMenu);
watchjMenu.setText("查看");
sleanjMenuItem.setText("查分");
sleanjMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sleanjMenuItemActionPerformed(evt);
}
});
watchjMenu.add(sleanjMenuItem);
amendpassjMenuItem.setText("修改密码");
amendpassjMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
amendpassjMenuItemActionPerformed(evt);
}
});
watchjMenu.add(amendpassjMenuItem);
jMenuBar1.add(watchjMenu);
aboutjMenu.setText("关于");
aboutExamMenuItem.setText("本次考试");
aboutExamMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aboutExamMenuItemActionPerformed(evt);
}
});
aboutjMenu.add(aboutExamMenuItem);
jMenuBar1.add(aboutjMenu);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400, Short.MAX_VALUE));
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 279, Short.MAX_VALUE));
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
pack();
}
private void openjMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
java.io.File file = new java.io.File("save.txt");
try {
java.io.FileInputStream in = new java.io.FileInputStream(file);
byte byt[] = new byte[1024];
int len = in.read(byt);
String strid = new String(byt, 0, len);
int id = Integer.parseInt(strid);
MyFindUserDao findUser = new MyFindUserDao();
User user = new User();
user.setId(id);
User use = findUser.getUserID(user);
System.out.println("AAA" + use.getId());
if (use.getHaveIn() == 0) {
ExamPage exampage = new ExamPage();
exampage.setVisible(true);
exampage.setLocationRelativeTo(null);
InsertUserDao insertUser = new InsertUserDao();
use.setHaveIn(1);
boolean b = insertUser.setUserHaveIn(use);
} else if (use.getHaveIn() == 1) {
JOptionPane.showMessageDialog(this, "你已经参加完考试了!", "信息对话框", JOptionPane.WARNING_MESSAGE);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private void closeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
int n = JOptionPane.showConfirmDialog(this, "确定要退出考试吗?", "确认对话框", JOptionPane.WARNING_MESSAGE);
if (n == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
private void sleanjMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
java.io.File file = new java.io.File("save.txt");
try {
java.io.FileInputStream in = new java.io.FileInputStream(file);
byte byt[] = new byte[1024];
int len = in.read(byt);
String strid = new String(byt, 0, len);
int id = Integer.parseInt(strid);
FindGrade findGrade = new FindGrade();
Grade grage = new Grade();
grage.setId(id);
Grade gra = findGrade.getGradeID(grage);
int radioMark = gra.getRadioResult();
int fullMark = gra.getFullResule();
int judgeMark = gra.getEsitResult();
int bastMark = gra.getBatsisResult();
int sum = radioMark + fullMark + judgeMark;
JOptionPane.showMessageDialog(this, "单选题得分:" + radioMark + "\n" + "多选题得分:" + fullMark + "\n" + "判断题得分:"
+ judgeMark + "\n" + "总分:" + sum, "信息对话框", JOptionPane.WARNING_MESSAGE);
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private void amendpassjMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
ChangePassWordFrame setPassWord = new ChangePassWordFrame();
setPassWord.setVisible(true);
setPassWord.setTitle("修改密码");
setPassWord.setBounds(200, 150, 400, 300);
setPassWord.setLocationRelativeTo(null);
}
private void aboutExamMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
AboutFrame myAbout = new AboutFrame();
myAbout.setVisible(true);
myAbout.setTitle("关于本次考试");
myAbout.setBounds(200, 150, 450, 350);
myAbout.setLocationRelativeTo(null);
}
private javax.swing.JMenu FilejMenu;
private javax.swing.JMenuItem aboutExamMenuItem;
private javax.swing.JMenu aboutjMenu;
private javax.swing.JMenuItem amendpassjMenuItem;
private javax.swing.JMenuItem closeMenuItem;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem openjMenuItem;
private javax.swing.JMenuItem sleanjMenuItem;
private javax.swing.JMenu watchjMenu;
private MySudentExamJPanel jPanel;
}
/*
* AddJudge.java
*
* Created on 2008年8月9日, 下午5:02
*/
package com.sjsq.controller;
import javax.swing.JOptionPane;
import com.sjsq.bean.*;
import com.sjsq.dao.FindQuestionDao;
/**
*
* @author Administrator
*/
public class AddJudgeFrame extends javax.swing.JFrame {
// 增加判断
/** Creates new form AddJudge */
public AddJudgeFrame() {
// 构造方法
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// // Code">//GEN-BEGIN:initComponents
private void initComponents() {
// 初始化方法
jLabel1 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
addJudgejLabel = new javax.swing.JLabel();
idCountjLabel = new javax.swing.JLabel();
idjTextField = new javax.swing.JTextField();
idCountjLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
NamejTextArea = new javax.swing.JTextArea();
answerJLabel = new javax.swing.JLabel();
answerjTextField1 = new javax.swing.JTextField();
addjButton = new javax.swing.JButton();
resjButton = new javax.swing.JButton();
resjButton1 = new javax.swing.JButton();
remarkLabel = new javax.swing.JLabel();
remarkjTextField = new javax.swing.JTextField();
jLabel1.setText("");
setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
// 关闭窗口监听方法
formWindowClosing(evt);
}
});
setTitle("添加判断题");
addJudgejLabel.setText("添加判断题模块:");
idCountjLabel.setText("试题编号:");
FindQuestionDao findDao = new FindQuestionDao();
int id = findDao.findQMid();
idjTextField.setText("" + (id + 1));
idjTextField.setEditable(false);
idCountjLabel1.setText("试题题目:");
NamejTextArea.setColumns(20);
NamejTextArea.setRows(5);
jScrollPane1.setViewportView(NamejTextArea);
answerJLabel.setText("试题答案:");
answerjTextField1.setText("");
addjButton.setText("添加");
addjButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addjButtonActionPerformed(evt);
}
});
resjButton.setText("重置");
resjButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resjButtonActionPerformed(evt);
}
});
resjButton1.setText("关闭");
resjButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resjButton1ActionPerformed(evt);
}
});
remarkLabel.setText(" 备 注:");
remarkjTextField.setText("");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup().addContainerGap(100, Short.MAX_VALUE)
.addComponent(addJudgejLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 186,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(105, 105, 105))
.addGroup(jPanel1Layout.createSequentialGroup().addGap(82, 82, 82).addComponent(addjButton)
.addGap(18, 18, 18).addComponent(resjButton).addGap(18, 18, 18).addComponent(resjButton1)
.addContainerGap(102, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup().addGap(27, 27, 27).addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(remarkLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 66,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(
remarkjTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup().addComponent(idCountjLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(idjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 254,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup().addComponent(idCountjLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup().addComponent(answerJLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(
answerjTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)))
.addGap(46, 46, 46)));
jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(addJudgejLabel)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(idCountjLabel).addComponent(idjTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(idCountjLabel1)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(8, 8, 8)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(answerJLabel)
.addComponent(answerjTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(remarkLabel)
.addComponent(remarkjTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(addjButton).addComponent(resjButton).addComponent(resjButton1))
.addContainerGap()));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 280,
Short.MAX_VALUE));
pack();
}
private void addjButtonActionPerformed(java.awt.event.ActionEvent evt) {
if (NamejTextArea.getText().equals("")) {
JOptionPane.showMessageDialog(this, "试题题目不能为空!", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (answerjTextField1.getText().equals("")) {
JOptionPane.showMessageDialog(this, "试题答案不能为空!", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (!(answerjTextField1.getText().equals("正确")) && !(answerjTextField1.getText().equals("错误"))) {
JOptionPane.showMessageDialog(this, "试题答案只能是‘正确’或‘错误’两种!", "消息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
Question question = new Question();
question.setId(Integer.parseInt(idjTextField.getText()));
FindQuestionDao findQuestion = new FindQuestionDao();
QuestionType qtype = new QuestionType();
qtype.setQName("判断题");
QuestionType questype = findQuestion.getQuestionTypeID(qtype);
question.setTypeid(questype.getId());
question.setQ_subject(ChDeal.toISO(NamejTextArea.getText()));
question.setQ_answer(ChDeal.toISO(answerjTextField1.getText()));
question.setOptionA("");
question.setOptionB("");
question.setOptionC("");
question.setOptionD("");
System.out.println("sssssssssssssssssssss " + remarkjTextField.getText());
question.setNote(remarkjTextField.getText());
boolean bool = findQuestion.setQuestionDBbean(question);
if (bool == true) {
JOptionPane.showMessageDialog(this, "判断题添加成功!", "信息对话框", JOptionPane.WARNING_MESSAGE);
dispose();
AdminMainFrame cont = new AdminMainFrame();
cont.setVisible(true);
cont.setLocationRelativeTo(null);
}
}
private void resjButtonActionPerformed(java.awt.event.ActionEvent evt) {
NamejTextArea.setText("");
answerjTextField1.setText("");
remarkjTextField.setText("");
}
private void resjButton1ActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
AdminMainFrame controller = new AdminMainFrame();
controller.setVisible(true);
controller.setBounds(100, 200, 650, 450);
controller.setLocationRelativeTo(null);
}
private void formWindowClosing(java.awt.event.WindowEvent evt) {
dispose();
AdminMainFrame controll = new AdminMainFrame();
controll.setVisible(true);
controll.setLocationRelativeTo(null);
}
/**
* @param args
* the command line arguments
*/
private javax.swing.JTextArea NamejTextArea;
private javax.swing.JLabel addJudgejLabel;
private javax.swing.JButton addjButton;
private javax.swing.JLabel answerJLabel;
private javax.swing.JTextField answerjTextField1;
private javax.swing.JLabel idCountjLabel;
private javax.swing.JLabel idCountjLabel1;
private javax.swing.JTextField idjTextField;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel remarkLabel;
private javax.swing.JTextField remarkjTextField;
private javax.swing.JButton resjButton;
private javax.swing.JButton resjButton1;
}
/*
* AddRadioFrame.java
*
* Created on 2008年8月9日, 下午2:45
*/
package com.sjsq.controller;
import javax.swing.JOptionPane;
import com.sjsq.bean.*;
import com.sjsq.dao.FindQuestionDao;
/**
*
* @author Administrator
*/
public class AddMoreFrame extends javax.swing.JFrame {
// 多选题
/** Creates new form AddRadioFrame */
public AddMoreFrame() {
// 构造方法
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// // Code">//GEN-BEGIN:initComponents
private void initComponents() {
// 初始化方法
jLabel2 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
messageLabel = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
idTextField = new javax.swing.JTextField();
NameJLabel = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
NamejTextArea = new javax.swing.JTextArea();
jSeparator1 = new javax.swing.JSeparator();
answerJLabel = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
optionATextField = new javax.swing.JTextField();
answerB = new javax.swing.JLabel();
optionBTextField = new javax.swing.JTextField();
answerC = new javax.swing.JLabel();
optionCTextField = new javax.swing.JTextField();
answerC1 = new javax.swing.JLabel();
optionDTextField = new javax.swing.JTextField();
jSeparator2 = new javax.swing.JSeparator();
jLabel4 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
addjButton = new javax.swing.JButton();
resButton = new javax.swing.JButton();
noteTextField = new javax.swing.JTextField();
closejButton = new javax.swing.JButton();
jLabel2.setText("jLabel2");
setSize(400, 600);
setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
messageLabel.setText("增加多选题模块,要填满一下所有各项。");
FindQuestionDao findDao = new FindQuestionDao();
java.util.List list = findDao.findQuestion();
int id = 0;// 题目编号
if (list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
Question question = (Question) list.get(i);
id = question.getId();// 获取list集合中所有的试题id
}
}
jLabel1.setText("题目编号:");
idTextField.setText("" + (id + 1));
idTextField.setEditable(false);
NameJLabel.setText("题目题目:");
NamejTextArea.setColumns(20);
NamejTextArea.setRows(5);
jScrollPane1.setViewportView(NamejTextArea);
answerJLabel.setText("备选答案区:");
jLabel3.setText("答案A:");
answerB.setText("答案B:");
answerC.setText("答案C:");
answerC1.setText("答案D:");
jLabel4.setText("答案:");
jLabel5.setText("备 注:");
addjButton.setText("添加");
addjButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addjButtonActionPerformed(evt);
}
});
resButton.setText("重置");
resButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resButtonActionPerformed(evt);
}
});
closejButton.setText("退出");
closejButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closejButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup().addContainerGap(66, Short.MAX_VALUE)
.addComponent(messageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 304,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(jPanel1Layout.createSequentialGroup().addGap(98, 98, 98).addComponent(addjButton)
.addGap(18, 18, 18).addComponent(resButton).addGap(18, 18, 18).addComponent(closejButton)
.addContainerGap())
.addGroup(jPanel1Layout.createSequentialGroup().addGap(37, 37, 37).addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 308,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup().addGap(22, 22, 22).addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 230,
Short.MAX_VALUE)
.addGap(51, 51, 51))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup().addGap(18, 18, 18).addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
.addComponent(answerC,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(answerB,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(
answerC1, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(noteTextField,
javax.swing.GroupLayout.DEFAULT_SIZE, 231,
Short.MAX_VALUE)
.addComponent(optionDTextField,
javax.swing.GroupLayout.DEFAULT_SIZE, 231,
Short.MAX_VALUE)
.addComponent(optionCTextField,
javax.swing.GroupLayout.DEFAULT_SIZE, 231,
Short.MAX_VALUE)
.addComponent(optionBTextField,
javax.swing.GroupLayout.DEFAULT_SIZE, 231,
Short.MAX_VALUE)
.addComponent(optionATextField,
javax.swing.GroupLayout.DEFAULT_SIZE, 231,
Short.MAX_VALUE))
.addGap(48, 48, 48))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(answerJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 90,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
jPanel1Layout.createSequentialGroup().addComponent(jLabel1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(idTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, 231,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
jPanel1Layout.createSequentialGroup().addComponent(NameJLabel)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.DEFAULT_SIZE, 231,
Short.MAX_VALUE)))
.addGap(48, 48, 48))))));
jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(messageLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1).addComponent(idTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addGap(10, 10, 10).addComponent(
jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 71,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup().addGap(35, 35, 35)
.addComponent(NameJLabel)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(answerJLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3).addComponent(optionATextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(answerB).addComponent(optionBTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(answerC).addComponent(optionCTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(answerC1).addComponent(optionDTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(noteTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addGap(13, 13, 13)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(addjButton).addComponent(resButton).addComponent(closejButton))
.addContainerGap(31, Short.MAX_VALUE)));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup().addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap()));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
pack();
}
private void addjButtonActionPerformed(java.awt.event.ActionEvent evt) {
if (NamejTextArea.getText().equals("")) {
JOptionPane.showMessageDialog(this, "试题题目不能为空", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (optionATextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "选项A不能为空", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (optionBTextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "选项B不能为空", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (optionCTextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "选项C不能为空", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (optionDTextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "选项D不能为空", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (noteTextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "需要添加备注", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if ((jTextField1.getText().length() > 1) && (jTextField1.getText().indexOf(",") == -1)) {
JOptionPane.showMessageDialog(this, "多选题要求答案格式如:'A,B,C,D'", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
FindQuestionDao findQuestion = new FindQuestionDao();
Question question = new Question();
question.setId(Integer.parseInt(idTextField.getText()));
question.setQ_subject(ChDeal.toISO(NamejTextArea.getText()));
question.setQ_answer(ChDeal.toISO(jTextField1.getText()));
question.setOptionA(ChDeal.toISO(optionATextField.getText()));
QuestionType questionType = new QuestionType();
questionType.setQName(ChDeal.toISO("多选题"));
QuestionType qtype = findQuestion.getQuestionTypeID(questionType);
question.setTypeid(qtype.getId());
question.setOptionB(ChDeal.toISO(optionBTextField.getText()));
question.setOptionC(ChDeal.toISO(optionCTextField.getText()));
question.setOptionD(ChDeal.toISO(optionDTextField.getText()));
question.setNote(noteTextField.getText());
boolean bool = findQuestion.setQuestionDBbean(question);
if (bool == true) {
JOptionPane.showMessageDialog(this, "信息添加成功", "信息对话框", JOptionPane.WARNING_MESSAGE);
dispose();
AdminMainFrame controllerFrame = new AdminMainFrame();
controllerFrame.setVisible(true);
controllerFrame.setLocationRelativeTo(null);
}
}
private void resButtonActionPerformed(java.awt.event.ActionEvent evt) {
NamejTextArea.setText("");
jTextField1.setText("");
optionATextField.setText("");
optionBTextField.setText("");
optionCTextField.setText("");
optionDTextField.setText("");
}
// 关闭窗口,返回主页面
private void closejButtonActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
AdminMainFrame controller = new AdminMainFrame();
controller.setVisible(true);
controller.setBounds(100, 200, 650, 450);
controller.setLocationRelativeTo(null);
}
private void formWindowClosing(java.awt.event.WindowEvent evt) {
dispose();
AdminMainFrame controll = new AdminMainFrame();
controll.setVisible(true);
controll.setLocationRelativeTo(null);
}
/**
* @param args
* the command line arguments
*/
private javax.swing.JLabel NameJLabel;
private javax.swing.JButton addjButton;
private javax.swing.JLabel answerB;
private javax.swing.JLabel answerC;
private javax.swing.JLabel answerC1;
private javax.swing.JLabel answerJLabel;
private javax.swing.JButton closejButton;
private javax.swing.JTextField idTextField;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JTextArea NamejTextArea;
private javax.swing.JTextField jTextField1;
private javax.swing.JLabel messageLabel;
private javax.swing.JTextField noteTextField;
private javax.swing.JTextField optionATextField;
private javax.swing.JTextField optionBTextField;
private javax.swing.JTextField optionCTextField;
private javax.swing.JTextField optionDTextField;
private javax.swing.JButton resButton;
}
/*
* AddRadioFrame.java
*
* Created on 2008年8月9日, 下午2:45
*/
package com.sjsq.controller;
import javax.swing.JOptionPane;
import com.sjsq.bean.*;
import com.sjsq.dao.FindQuestionDao;
/**
*
* @author Administrator
*/
public class AddRadioFrame extends javax.swing.JFrame {
// 单选题
/** Creates new form AddRadioFrame */
public AddRadioFrame() {
// 构造方法
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// // Code">//GEN-BEGIN:initComponents
private void initComponents() {
// 初始化方法
jLabel2 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
messageLabel = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
idTextField = new javax.swing.JTextField();
NameJLabel = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
NamejTextArea = new javax.swing.JTextArea();
jSeparator1 = new javax.swing.JSeparator();
answerJLabel = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
optionATextField = new javax.swing.JTextField();
answerB = new javax.swing.JLabel();
optionBTextField = new javax.swing.JTextField();
answerC = new javax.swing.JLabel();
optionCTextField = new javax.swing.JTextField();
answerC1 = new javax.swing.JLabel();
optionDTextField = new javax.swing.JTextField();
jSeparator2 = new javax.swing.JSeparator();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
note = new javax.swing.JTextField();
jTextField1 = new javax.swing.JTextField();
addjButton = new javax.swing.JButton();
resButton = new javax.swing.JButton();
closejButton = new javax.swing.JButton();
jLabel2.setText("jLabel2");
setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
messageLabel.setText("增加单选题模块,要填满一下所有各项。");
FindQuestionDao findDao = new FindQuestionDao();
int id = findDao.findQMid();// 获得最大的id号
jLabel1.setText("题目编号:");
idTextField.setText("" + (id + 1));
idTextField.setEditable(false);
NameJLabel.setText("题目题目:");
NamejTextArea.setColumns(20);
NamejTextArea.setRows(5);
jScrollPane1.setViewportView(NamejTextArea);
answerJLabel.setText("备选答案区:");
jLabel3.setText("答案A:");
answerB.setText("答案B:");
answerC.setText("答案C:");
answerC1.setText("答案D:");
jLabel4.setText("答案:");
jLabel5.setText("备注");
addjButton.setText("添加");
addjButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addjButtonActionPerformed(evt);
}
});
resButton.setText("重置");
resButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resButtonActionPerformed(evt);
}
});
closejButton.setText("退出");
closejButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closejButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup().addContainerGap(66, Short.MAX_VALUE)
.addComponent(messageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 304,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(jPanel1Layout.createSequentialGroup().addGap(98, 98, 98).addComponent(addjButton)
.addGap(18, 18, 18).addComponent(resButton).addGap(18, 18, 18).addComponent(closejButton)
.addContainerGap())
.addGroup(jPanel1Layout.createSequentialGroup().addGap(37, 37, 37).addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 308,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup().addGap(22, 22, 22).addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 230,
Short.MAX_VALUE)
.addGap(51, 51, 51))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup().addGap(18, 18, 18).addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
.addComponent(answerC,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(answerB,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(
answerC1, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(note, javax.swing.GroupLayout.DEFAULT_SIZE, 231,
Short.MAX_VALUE)
.addComponent(optionDTextField,
javax.swing.GroupLayout.DEFAULT_SIZE, 231,
Short.MAX_VALUE)
.addComponent(optionCTextField,
javax.swing.GroupLayout.DEFAULT_SIZE, 231,
Short.MAX_VALUE)
.addComponent(optionBTextField,
javax.swing.GroupLayout.DEFAULT_SIZE, 231,
Short.MAX_VALUE)
.addComponent(optionATextField,
javax.swing.GroupLayout.DEFAULT_SIZE, 231,
Short.MAX_VALUE))
.addGap(48, 48, 48))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(answerJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 90,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
jPanel1Layout.createSequentialGroup().addComponent(jLabel1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(idTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, 231,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
jPanel1Layout.createSequentialGroup().addComponent(NameJLabel)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.DEFAULT_SIZE, 231,
Short.MAX_VALUE)))
.addGap(48, 48, 48))))));
jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(messageLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1).addComponent(idTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addGap(10, 10, 10).addComponent(
jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 71,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup().addGap(35, 35, 35)
.addComponent(NameJLabel)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(answerJLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3).addComponent(optionATextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(answerB).addComponent(optionBTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(answerC).addComponent(optionCTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(answerC1).addComponent(optionDTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(note, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addGap(13, 13, 13)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(addjButton).addComponent(resButton).addComponent(closejButton))
.addContainerGap(31, Short.MAX_VALUE)));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup().addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap()));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
pack();
}
private void addjButtonActionPerformed(java.awt.event.ActionEvent evt) {
if (NamejTextArea.getText().equals("")) {
JOptionPane.showMessageDialog(this, "试题题目不能为空", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (optionATextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "选项A不能为空", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (optionBTextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "选项B不能为空", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (optionCTextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "选项C不能为空", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (optionDTextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "选项D不能为空", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (note.getText().equals("")) {
JOptionPane.showMessageDialog(this, "备注不能为空", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (!jTextField1.getText().equals("A")
&& !(jTextField1.getText().equals("B") && !(jTextField1.getText().equals("C"))
&& !(jTextField1.getText().equals("D")) && (jTextField1.getText()).length() > 1)) {
JOptionPane.showMessageDialog(this, "答案必须是'A','B','C','D'其中的一项", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
FindQuestionDao findQuestion = new FindQuestionDao();
Question question = new Question();
question.setId(Integer.parseInt(idTextField.getText()));
question.setQ_subject(ChDeal.toISO(NamejTextArea.getText()));
question.setQ_answer(ChDeal.toISO(jTextField1.getText()));
question.setOptionA(ChDeal.toISO(optionATextField.getText()));
QuestionType questionType = new QuestionType();// 实例化试题类型
questionType.setQName(ChDeal.toISO("单选题"));
QuestionType qtype = findQuestion.getQuestionTypeID(questionType);// 获得套题编号
question.setTypeid(qtype.getId());
question.setOptionB(ChDeal.toISO(optionBTextField.getText()));
question.setOptionC(ChDeal.toISO(optionCTextField.getText()));
question.setOptionD(ChDeal.toISO(optionDTextField.getText()));
question.setNote(note.getText());
boolean bool = findQuestion.setQuestionDBbean(question);
if (bool == true) {
JOptionPane.showMessageDialog(this, "信息添加成功", "信息对话框", JOptionPane.WARNING_MESSAGE);
dispose();
AdminMainFrame controll = new AdminMainFrame();
controll.setVisible(true);
controll.setLocationRelativeTo(null);
}
}
private void resButtonActionPerformed(java.awt.event.ActionEvent evt) {
NamejTextArea.setText("");
jTextField1.setText("");
optionATextField.setText("");
optionBTextField.setText("");
optionCTextField.setText("");
optionDTextField.setText("");
}
private void closejButtonActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
AdminMainFrame controller = new AdminMainFrame();
controller.setVisible(true);
controller.setBounds(100, 200, 650, 450);
controller.setLocationRelativeTo(null);
}
private void formWindowClosing(java.awt.event.WindowEvent evt) {
dispose();
AdminMainFrame controll = new AdminMainFrame();
controll.setVisible(true);
controll.setLocationRelativeTo(null);
}
private javax.swing.JLabel NameJLabel;
private javax.swing.JButton addjButton;
private javax.swing.JLabel answerB;
private javax.swing.JLabel answerC;
private javax.swing.JLabel answerC1;
private javax.swing.JLabel answerJLabel;
private javax.swing.JButton closejButton;
private javax.swing.JTextField idTextField;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JTextArea NamejTextArea;
private javax.swing.JTextField jTextField1;
private javax.swing.JLabel messageLabel;
private javax.swing.JTextField optionATextField;
private javax.swing.JTextField optionBTextField;
private javax.swing.JTextField optionCTextField;
private javax.swing.JTextField optionDTextField;
private javax.swing.JTextField note;
private javax.swing.JButton resButton;
}
/*
* testFrame.java
*
* Created on 2008年8月8日, 上午8:30
*/
package com.sjsq.controller;
import javax.swing.JOptionPane;
import com.sjsq.bean.*;
import com.sjsq.dao.FindQuestionDao;
/**
*
* @author Administrator
*/
public class AddExamFrame extends javax.swing.JFrame {
/** Creates new form testFrame */
public AddExamFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// // Code">//GEN-BEGIN:initComponents
private void initComponents() {
jFrame1 = new javax.swing.JFrame();
noteTextField = new javax.swing.JPanel();
testQuestionMessage = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
qSubjectjTextArea = new javax.swing.JTextArea();
testQuestionId = new javax.swing.JLabel();
qidjTextField = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
qTypejComboBox = new javax.swing.JComboBox();
jSeparator1 = new javax.swing.JSeparator();
answerMessage = new javax.swing.JLabel();
optionA = new javax.swing.JLabel();
optionTextField = new javax.swing.JTextField();
optionB = new javax.swing.JLabel();
optionBTextField = new javax.swing.JTextField();
optionC = new javax.swing.JLabel();
optionCjTextField = new javax.swing.JTextField();
optionD = new javax.swing.JLabel();
optionDTextField = new javax.swing.JTextField();
jSeparator2 = new javax.swing.JSeparator();
answermessage = new javax.swing.JLabel();
qanswerTextField = new javax.swing.JTextField();
saveButton = new javax.swing.JButton();
canceljButton = new javax.swing.JButton();
noteMessage = new javax.swing.JLabel();
noteField = new javax.swing.JTextField();
javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE));
jFrame1Layout.setVerticalGroup(jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE));
setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
});
testQuestionMessage.setText("试题题目:");
qSubjectjTextArea.setColumns(20);
qSubjectjTextArea.setRows(5);
jScrollPane1.setViewportView(qSubjectjTextArea);
testQuestionId.setText("试题编号:");
int id = 0;
FindQuestionDao findQuestion = new FindQuestionDao();
java.util.List<Question> questList = findQuestion.findQuestion();
if (questList.size() > 0) {
for (int i = 0; i < questList.size(); i++) {
Question question = questList.get(i);
id = question.getId();
}
}
int ids = findQuestion.findQMid();
int qid = ids + 1;
qidjTextField.setText("" + qid);
qidjTextField.setEnabled(false);
jLabel1.setText("试题类型:");
qTypejComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
"单选题", "多选题", "" + "判断题" }));
answerMessage.setText("题目选项部分,如果是判断题该部分内容可以省略:");
optionA.setText("A:");
optionTextField.setText("");
optionB.setText("B:");
optionBTextField.setText("");
optionC.setText("C:");
optionCjTextField.setText("");
optionD.setText("D:");
optionDTextField.setText("");
answermessage.setText(" 答 案:");
qanswerTextField.setText("");
saveButton.setText("保存");
saveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveButtonActionPerformed(evt);
}
});
canceljButton.setText("重置");
canceljButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
canceljButtonActionPerformed(evt);
}
});
noteMessage.setText(" 备 注:");
noteField.setText("");
javax.swing.GroupLayout noteTextFieldLayout = new javax.swing.GroupLayout(noteTextField);
noteTextField.setLayout(noteTextFieldLayout);
noteTextFieldLayout.setHorizontalGroup(noteTextFieldLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(noteTextFieldLayout.createSequentialGroup().addGroup(noteTextFieldLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, 405, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, noteTextFieldLayout
.createSequentialGroup().addGap(22, 22, 22)
.addGroup(noteTextFieldLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(noteTextFieldLayout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(testQuestionId)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(qidjTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 319,
Short.MAX_VALUE))
.addGroup(noteTextFieldLayout.createSequentialGroup()
.addComponent(testQuestionMessage)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 319,
Short.MAX_VALUE))
.addGroup(noteTextFieldLayout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(qTypejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
104, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(215, 215, 215))))
.addGroup(noteTextFieldLayout.createSequentialGroup().addGap(59, 59, 59)
.addGroup(noteTextFieldLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(noteTextFieldLayout.createSequentialGroup().addComponent(optionB)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(optionBTextField, javax.swing.GroupLayout.DEFAULT_SIZE,
318, Short.MAX_VALUE))
.addGroup(noteTextFieldLayout.createSequentialGroup().addComponent(optionA)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(optionTextField, javax.swing.GroupLayout.DEFAULT_SIZE,
318, Short.MAX_VALUE))
.addGroup(noteTextFieldLayout.createSequentialGroup().addComponent(optionC)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(optionCjTextField, javax.swing.GroupLayout.DEFAULT_SIZE,
318, Short.MAX_VALUE))
.addGroup(noteTextFieldLayout.createSequentialGroup().addComponent(optionD)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(optionDTextField, javax.swing.GroupLayout.DEFAULT_SIZE,
318, Short.MAX_VALUE))))
.addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 405, Short.MAX_VALUE)
.addGroup(noteTextFieldLayout.createSequentialGroup().addGap(36, 36, 36).addComponent(
answerMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 300,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(noteTextFieldLayout.createSequentialGroup().addGap(21, 21, 21)
.addGroup(noteTextFieldLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(noteTextFieldLayout.createSequentialGroup()
.addComponent(noteMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(noteField, javax.swing.GroupLayout.DEFAULT_SIZE, 316,
Short.MAX_VALUE))
.addGroup(noteTextFieldLayout.createSequentialGroup()
.addComponent(answermessage, javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(qanswerTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
129, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32).addComponent(saveButton).addGap(18, 18, 18)
.addComponent(canceljButton)))))
.addContainerGap()));
noteTextFieldLayout.setVerticalGroup(noteTextFieldLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(noteTextFieldLayout.createSequentialGroup()
.addGroup(noteTextFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(qidjTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(testQuestionId))
.addGap(9, 9, 9)
.addGroup(noteTextFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(testQuestionMessage).addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE, 89,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(noteTextFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(qTypejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(answerMessage)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(noteTextFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(optionTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(optionA))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(noteTextFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(optionB).addComponent(optionBTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(noteTextFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(optionC)
.addComponent(optionCjTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(noteTextFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(optionD)
.addComponent(optionDTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(9, 9, 9)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 11,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(noteTextFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(noteMessage)
.addComponent(noteField, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(14, 14, 14)
.addGroup(noteTextFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(qanswerTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(answermessage).addComponent(saveButton).addComponent(canceljButton))
.addContainerGap(18, Short.MAX_VALUE)));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup().addContainerGap().addComponent(noteTextField,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(29, 29, 29)));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup().addContainerGap().addComponent(noteTextField,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)));
pack();
}
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
if (qSubjectjTextArea.getText().equals("")) {
JOptionPane.showMessageDialog(this, "请输入考试题目", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (qanswerTextField.getText().equals("")) {
JOptionPane.showMessageDialog(this, "请输入考题答案", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if ((qTypejComboBox.getSelectedItem().toString().equals("多选题")) && (qanswerTextField.getText().length() > 0)
&& (qanswerTextField.getText().indexOf(",") == -1)) {
JOptionPane.showMessageDialog(this, "多选题的答案要求格式如:'A,B,C,D'", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (qTypejComboBox.getSelectedItem().toString().equals("判断题")) {
if (!(qanswerTextField.getText().equals("正确")) && !(qanswerTextField.getText().equals("错误"))) {
JOptionPane.showMessageDialog(this, "试题答案只能是‘正确’或‘错误’两种!", "消息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
}
Question question = new Question();
question.setId(Integer.parseInt(qidjTextField.getText()));
FindQuestionDao insertQuestion = new FindQuestionDao();
QuestionType questionType = new QuestionType();
questionType.setQName(ChDeal.toISO(qTypejComboBox.getSelectedItem().toString()));
QuestionType qtype = insertQuestion.getQuestionType(questionType);
question.setTypeid(qtype.getId());
question.setQ_subject(ChDeal.toISO(qSubjectjTextArea.getText()));
question.setQ_answer(ChDeal.toISO(qanswerTextField.getText().trim()));
question.setOptionA(ChDeal.toISO(optionTextField.getText()));
question.setOptionB(ChDeal.toISO(optionBTextField.getText()));
question.setOptionC(ChDeal.toISO(optionCjTextField.getText()));
question.setOptionD(ChDeal.toISO(optionDTextField.getText()));
question.setNote(ChDeal.toISO(noteField.getText()));
insertQuestion.setQuestionDBbean(question);
int n = JOptionPane.showConfirmDialog(this, "确定输入的数据正确吗啊?", "信息对话框", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(this, "考题添加成功", "信息对话框", JOptionPane.WARNING_MESSAGE);
dispose();
AdminMainFrame con = new AdminMainFrame();
con.setVisible(true);
con.setLocationRelativeTo(null);
}
}
private void formWindowClosed(java.awt.event.WindowEvent evt) {
dispose();
AdminMainFrame controllFrame = new AdminMainFrame();
controllFrame.setVisible(true);
controllFrame.setLocationRelativeTo(null);
}
private void canceljButtonActionPerformed(java.awt.event.ActionEvent evt) {
qSubjectjTextArea.setText("");
qanswerTextField.setText("");
optionTextField.setText("");
optionBTextField.setText("");
optionCjTextField.setText("");
optionDTextField.setText("");
noteField.setText("");
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel answerMessage;
private javax.swing.JLabel answermessage;
private javax.swing.JButton canceljButton;
private javax.swing.JComboBox qTypejComboBox;
private javax.swing.JFrame jFrame1;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JTextArea qSubjectjTextArea;
private javax.swing.JTextField qidjTextField;
private javax.swing.JTextField qanswerTextField;
private javax.swing.JTextField noteField;
private javax.swing.JLabel noteMessage;
private javax.swing.JPanel noteTextField;
private javax.swing.JLabel optionA;
private javax.swing.JLabel optionB;
private javax.swing.JTextField optionBTextField;
private javax.swing.JLabel optionC;
private javax.swing.JTextField optionCjTextField;
private javax.swing.JLabel optionD;
private javax.swing.JTextField optionDTextField;
private javax.swing.JTextField optionTextField;
private javax.swing.JButton saveButton;
private javax.swing.JLabel testQuestionId;
private javax.swing.JLabel testQuestionMessage;
// End of variables declaration//GEN-END:variables
}
/*
* AddFrame.java
*
* Created on 2008年8月8日, 下午2:00
*/
package com.sjsq.controller;
import javax.swing.JOptionPane;
import com.sjsq.bean.*;
import com.sjsq.dao.*;
/**
*
* @author Administrator
*/
public class UserAddFrame extends javax.swing.JFrame {
/** Creates new form AddFrame */
public UserAddFrame() {
// 构造方法
initComponents();// 调用初始化组件
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// // Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
qTypejComboBox = new javax.swing.JComboBox();
userNameLabel = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
userPassWord = new javax.swing.JLabel();
jPasswordField1 = new javax.swing.JPasswordField();
okUserName = new javax.swing.JLabel();
jPasswordField2 = new javax.swing.JPasswordField();
addButton = new javax.swing.JButton();
reset = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
// 为窗口设置监听
public void windowClosing(java.awt.event.WindowEvent evt) {
// 关闭窗口
formWindowClosing(evt);// 调用窗口监听的方法
}
});
jLabel1.setText("用户类型:");
qTypejComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
"--请选择用户身份--", "考生", "管理员" }));
userNameLabel.setText("用户姓名:");
jTextField1.setText("");
userPassWord.setText("用户密码:");
jPasswordField1.setText("");
okUserName.setText("确认密码:");
jPasswordField2.setText("");
addButton.setText("添加");
addButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addButtonActionPerformed(evt);
}
});
reset.setText("重置");
reset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resetActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup().addGap(64, 64, 64)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup().addComponent(okUserName)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPasswordField2, 0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup().addComponent(userPassWord)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPasswordField1, 0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup().addComponent(userNameLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 165,
Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup().addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(qTypejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 165,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(74, 74, 74))
.addGroup(layout.createSequentialGroup().addGap(115, 115, 115).addComponent(addButton)
.addGap(31, 31, 31).addComponent(reset).addContainerGap(107, Short.MAX_VALUE)));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
.createSequentialGroup().addGap(39, 39, 39)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
.addComponent(qTypejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(userNameLabel).addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(userPassWord)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(okUserName).addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(reset)
.addComponent(addButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
pack();
}
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
String strQtype = qTypejComboBox.getSelectedItem().toString();// 获得前台选择的下拉列表内容
if (jTextField1.getText().equals("")) {
JOptionPane.showMessageDialog(this, "请输入用户姓名", "信息对话框", JOptionPane.WARNING_MESSAGE);// this表示此窗口
return;
}
if (!jPasswordField1.getText().equals(jPasswordField2.getText())) {
JOptionPane.showMessageDialog(this, "两次输入的密码不一致", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
User user = new User();
if (strQtype.equals("--请选择用户身份--")) {
JOptionPane.showMessageDialog(this, "请选择用户身份", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
if (strQtype.equals("考生")) {
user.setUserType(0);
}
if (strQtype.equals("管理员")) {
user.setUserType(1);
}
MyFindUserDao findUser = new MyFindUserDao();
java.util.List list = findUser.findUser();
for (int i = 0; i < list.size(); i++) {
User users = (User) list.get(i);
if (users.getUserName().equals(jTextField1.getText())) {
System.out.println("USERNAME " + users.getUserName());
JOptionPane.showMessageDialog(this, "该用户名已存在", "信息对话框", JOptionPane.WARNING_MESSAGE);
return;
}
}
int i = findUser.getUserID();
user.setUserName(jTextField1.getText());
MyMD5 myMD5 = new MyMD5();
user.setId(i + 1);
System.out.println("list " + list.size() + 1);
user.setPassWord(myMD5.createPassWord(jPasswordField1.getText()));
InsertUserDao insertUser = new InsertUserDao();
insertUser.setUserInfoToDBbean(user);
JOptionPane.showMessageDialog(this, "用户添加", "信息对话框", JOptionPane.WARNING_MESSAGE);
}
private void resetActionPerformed(java.awt.event.ActionEvent evt) {
// 重置的监听方法
jTextField1.setText("");
jPasswordField1.setText("");
jPasswordField2.setText("");
qTypejComboBox.setSelectedIndex(0);
}
private void formWindowClosing(java.awt.event.WindowEvent evt) {
// 关闭窗体的监听方法
dispose();
AdminMainFrame controll = new AdminMainFrame();
controll.setVisible(true);
controll.setLocationRelativeTo(null);
}
/**
* @param args
* the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new UserAddFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addButton;
private javax.swing.JComboBox qTypejComboBox;
private javax.swing.JLabel jLabel1;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JPasswordField jPasswordField2;
private javax.swing.JTextField jTextField1;
private javax.swing.JLabel okUserName;
private javax.swing.JButton reset;
private javax.swing.JLabel userNameLabel;
private javax.swing.JLabel userPassWord;
// End of variables declaration//GEN-END:variables
}
package com.sjsq.util;
import java.security.*;
import java.sql.*;
public class GetConn {
public Connection conn = null;
public ResultSet rs = null;
public Statement stmt = null;
public GetConn() {
// 构造方法
}
// 获取数据库连接方法
public Connection getConnection() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/exam_management_swing?serverTimezone=UTC",
"root", "admin");
} catch (SQLException e) {
e.printStackTrace();
} // 异常处理
return conn;// 按发法要求返回个Connection对象
}
/*
* 功能:执行查询语句
*/
public ResultSet executeQuery(String sql) {
try {
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
return rs;
}
/*
* 功能:执行更新操作
*/
public int executeUpdate(String sql) {
int result = 0;
try {
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
result = stmt.executeUpdate(sql);
} catch (SQLException ex) {
result = 0;
}
try {
stmt.close();
} catch (SQLException ex1) {
}
return result;
}
/*
* 功能:关闭数据库的连接
*/
public void close() {
try {
if (rs != null) {
rs.close();
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
try {
if (stmt != null) {
stmt.close();
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
try {
if (conn != null) {
conn.close();
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
package com.sjsq.dao;
import java.util.*;
import java.sql.*;
import com.sjsq.bean.*;
import com.sjsq.util.GetConn;
public class FindGrade {
GetConn getConn = new GetConn();
private Connection conn = getConn.getConnection();
// 查找所有学分用户
public List findGrade() {
String strSql = "select * from tb_grade";
Statement pstmt = null;
ResultSet rs = null;
List lstList = new ArrayList();
try {
pstmt = conn.createStatement();
rs = pstmt.executeQuery(strSql);
while (rs.next()) {
Grade grade = new Grade();
grade.setId(rs.getInt("id"));
grade.setUserName(rs.getString("userName"));
grade.setRadioResult(rs.getInt("radioResult"));
grade.setFullResule(rs.getInt("fullResule"));
grade.setEsitResult(rs.getInt("esitResult"));
grade.setBatsisResult(rs.getInt("batsisResult"));
grade.setDate(rs.getString("date"));
lstList.add(grade);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (pstmt != null) {
rs.close();
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return lstList;
}
// 按id号查询成绩方法
/**
* @param grade
* 对应考分表Java bean Grade对象
* @return Grade对象
*/
public Grade getGradeID(Grade grade) {
String strSql = "select * from tb_grade where id=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(strSql);
pstmt.setInt(1, grade.getId());
rs = pstmt.executeQuery();
while (rs.next()) {
grade.setId(rs.getInt("id"));
grade.setUserName(rs.getString("userName"));
grade.setRadioResult(rs.getInt("radioResult"));
grade.setFullResule(rs.getInt("fullResule"));
grade.setEsitResult(rs.getInt("esitResult"));
grade.setBatsisResult(rs.getInt("batsisResult"));
grade.setDate(rs.getString("date"));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (pstmt != null) {
rs.close();
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return grade;
}
// 按考生姓名查找考试成绩方法
/**
* @param grade
* 与数据表tb_stat对应的java bean Stat对象
* @return Stat对象
*/
public Grade getGradeName(Grade grade) {
String strSql = "select * from tb_grade where userName=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(strSql);
pstmt.setString(1, grade.getUserName());
rs = pstmt.executeQuery();
while (rs.next()) {
grade.setId(rs.getInt("id"));
grade.setUserName(rs.getString("userName"));
grade.setRadioResult(rs.getInt("radioResult"));
grade.setFullResule(rs.getInt("fullResule"));
grade.setEsitResult(rs.getInt("esitResult"));
grade.setBatsisResult(rs.getInt("batsisResult"));
grade.setDate(rs.getString("date"));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (pstmt != null) {
rs.close();
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return grade;
}
public static void main(String[] args) {
FindGrade fg = new FindGrade();
Grade f = new Grade();
f.setUserName("kk");
Grade g = fg.getGradeName(f);
System.out.println(g.getId());
}
}
package com.sjsq.dao;
import java.sql.*;
import java.util.*;
import com.sjsq.bean.*;
import com.sjsq.util.GetConn;
public class InsertUserDao {
GetConn getConn = new GetConn();
private Connection conn = getConn.getConnection();
// 增加用户
public boolean setUserInfoToDBbean(User userinfo) {
boolean blnrec = true;
String strSql = "insert into tb_user" + " values(?,?,?,?,?)";
System.out.println(strSql);
PreparedStatement pstmt = null;
MyMD5 md = new MyMD5();
try {
pstmt = conn.prepareStatement(strSql);
pstmt.setInt(1, userinfo.getId());
pstmt.setInt(2, userinfo.getUserType());
pstmt.setString(3, userinfo.getUserName());
pstmt.setString(4, md.createPassWord(userinfo.getPassWord()));
pstmt.setString(4, userinfo.getPassWord());
pstmt.setInt(5, userinfo.getHaveIn());
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
blnrec = false;
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return blnrec;
}
// 修改用户,用于判断用户是否已参加考试
/**
* @param userinfo
* 与用户表tb_use对应的Java bean
* @return 成功修改havaIn值返回true,否则返回false
*/
public boolean setUserHaveIn(User userinfo) {
boolean blnrec = true;
String strSql = "update tb_User set havaIn = ? where id = ?";
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(strSql);
pstmt.setInt(1, userinfo.getHaveIn());
pstmt.setInt(2, userinfo.getId());
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
blnrec = false;
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return blnrec;
}
// 修改用户信息
public boolean updateUserHaveIn(User userinfo) {
MyMD5 md = new MyMD5();
boolean blnrec = true;
String strSql = "update tb_user set userType =?,UserName=?,passWord=?,havaIn=? " + "where Id = ?";
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(strSql);
pstmt.setInt(1, userinfo.getUserType());
pstmt.setString(2, userinfo.getUserName());
pstmt.setString(3, userinfo.getPassWord());
pstmt.setInt(4, userinfo.getHaveIn());
pstmt.setInt(5, userinfo.getId());
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
blnrec = false;
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return blnrec;
}
// 修改用户信息二
public boolean updateUserHaveIn2(User userinfo) {
MyMD5 md = new MyMD5();
boolean blnrec = true;
String strSql = "update tb_user set userType =?,UserName=?,havaIn=? " + "where Id = ?";
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(strSql);
pstmt.setInt(1, userinfo.getUserType());
pstmt.setString(2, userinfo.getUserName());
pstmt.setInt(3, userinfo.getHaveIn());
pstmt.setInt(4, userinfo.getId());
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
blnrec = false;
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return blnrec;
}
// 修改用户密码信息
public boolean updateUserPassWord(User userinfo) {
boolean blnrec = true;
String strSql = "update tb_user set passWord=? " + "where Id = ?";
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(strSql);
MyMD5 mymd5 = new MyMD5();
// pstmt.setString(1, mymd5.createPassWord(userinfo.getPassWord()));
pstmt.setString(1, userinfo.getPassWord());
pstmt.setInt(2, userinfo.getId());
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
blnrec = false;
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return blnrec;
}
public static void main(String[] args) {
// User user = new User();
// MyMD5 md = new MyMD5();
// user.setId(99);
// user.setUserName("kkkkk");
// user.setHaveIn(0);
// user.setUserType(0);
InsertUserDao id = new InsertUserDao();
// boolean bool = id.setUserInfoToDBbean(user);
// System.out.println(user.getPassWord());
}
}
/*
* MyAbout.java
*
* Created on 2008年8月12日, 下午6:59
*/
package com.sjsq.view;
import java.net.*;
import javax.swing.*;
/**
*
* @author Administrator
*/
public class AboutFrame extends javax.swing.JFrame {
/** Creates new form MyAbout */
public AboutFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
private void initComponents() {
jSeparator1 = new javax.swing.JSeparator();
jPanel1 = new javax.swing.JPanel();
messageJLabel = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jSeparator2 = new javax.swing.JSeparator();
ruleMessage = new javax.swing.JLabel();
ruleJlabel = new javax.swing.JLabel();
ruleJlabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
messageJLabel.setText("考试系统:");
jLabel1.setText("本系统是完全按照上机考试的模式设计,本");
jLabel2.setText("次考试由单选题、多选题、判断题组成。");
ruleMessage.setText("考试规则:");
ruleJlabel.setText("单选题、判断题答题错误都不得分。多选题如果有多选、落选、");
ruleJlabel2.setText("错选、少选都不得分。本次考试的满分是100分。");
jButton1.setText("退出");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
URL url = getClass().getResource("/image/a.gif");
ImageIcon iamge = new ImageIcon(url);
jLabel3 = new javax.swing.JLabel(iamge);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout
.createSequentialGroup()
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 95,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addGap(28, 28, 28)
.addGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2,
javax.swing.GroupLayout.DEFAULT_SIZE, 259,
Short.MAX_VALUE)
.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 259,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createSequentialGroup().addGap(18, 18, 18)
.addComponent(messageJLabel,
javax.swing.GroupLayout.PREFERRED_SIZE, 66,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup().addGap(34, 34, 34).addComponent(
ruleJlabel, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup().addGap(10, 10, 10)
.addGroup(jPanel1Layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(ruleJlabel2, javax.swing.GroupLayout.DEFAULT_SIZE,
360, Short.MAX_VALUE)
.addComponent(ruleMessage,
javax.swing.GroupLayout.PREFERRED_SIZE, 66,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addComponent(jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE,
63,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18))))))
.addGap(18, 18, 18)));
jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup().addComponent(messageJLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel2))
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 85,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(ruleMessage)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(ruleJlabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(ruleJlabel2)
.addGap(28, 28, 28).addComponent(jButton1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
pack();
}//
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
StudentMainFrame studentExam = new StudentMainFrame();
studentExam.setVisible(true);
studentExam.setBounds(200, 200, 500, 400);
studentExam.setTitle("考试系统");
studentExam.setLocationRelativeTo(null);
}
private void formWindowClosing(java.awt.event.WindowEvent evt) {
dispose();
StudentMainFrame studentExam = new StudentMainFrame();
studentExam.setVisible(true);
studentExam.setBounds(150, 150, 500, 400);
studentExam.setLocationRelativeTo(null);
}
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JLabel messageJLabel;
private javax.swing.JLabel ruleJlabel;
private javax.swing.JLabel ruleJlabel2;
private javax.swing.JLabel ruleMessage;
}
Java+Swing实现仓库管理系统
Java+Swing实现学生信息管理系统
Java+Swing实现学生宿舍管理系统
Java+Swing实现学生选课管理系统
Java+Swing实现电子相册管理系统
Java+Swing实现图书管理系统
Java+Swing实现斗地主游戏
Java+Swing实现宠物商店管理系统
Java+Swing实现学生成绩管理系统
Java+Swing实现企业人事管理系统
Java+Swing实现学校教材管理系统
Java+Swing实现学校教务管理系统
Java+Swing实现超市管理系统-TXT存储信息
请联系QQ:3079118617
如有侵权请联系我删除。