AddJudgeFrame.java
/* * 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") // <editor-fold defaultstate="collapsed" desc="Generated // 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; }
AddMoreFrame.java
/* * 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") // <editor-fold defaultstate="collapsed" desc="Generated // 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
/* * 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") // <editor-fold defaultstate="collapsed" desc="Generated // 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; }
AddExamFrame.java
/* * 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") // <editor-fold defaultstate="collapsed" desc="Generated // 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 }
UserAddFrame.java
/* * 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") // <editor-fold defaultstate="collapsed" desc="Generated // 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 }
GetConn.java
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); } } }
FindGrade.java
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()); } }
InsertUserDao.java
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()); } }
AboutFrame.java
/* * 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") // <editor-fold defaultstate="collapsed" desc="Generated Code"> 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(); }// </editor-fold> 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; }
四、其他
1.其他系统实现
JavaWeb系统系列实现
Java+JSP实现学生图书管理系统
Java+JSP实现学生信息管理系统
Java+Servlet+JSP实现学生成绩管理系统
Java+Servlet+JSP实现宠物诊所管理系统
Java+SSM+Easyui实现网上考试系统
Java+Springboot+H-ui实现营销管理系统
Java+Springboot+Mybatis+Bootstrap实现网上商城系统
JavaSwing系统系列实现
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实现企业人事管理系统
Java+Swing实现电子相册管理系统
Java+Swing实现自助取款机(ATM)系统
Java+Swing实现超市管理系统-TXT存储信息
Java+Swing实现宠物商店管理系统-TXT存储信息
2.获取源码
点击以下链接获取源码
Java+Swing+Mysql考试管理系统源码
3.备注
如有侵权请联系我删除。
4.鸡汤
失意时,戒气馁。得意时,戒骄傲!