java考試系統(tǒng)源代碼eamsystem_第1頁
java考試系統(tǒng)源代碼eamsystem_第2頁
java考試系統(tǒng)源代碼eamsystem_第3頁
已閱讀5頁,還剩29頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、Question/* To change this template, choose Tools | Templates* and open the template in the editor.*/package ujn.ise.qsp.entity 。import java.io.Serializable 。* author Administrator*/public class Question implements Serializable private String title 。private String A 。private String B 。private String

2、C 。private String D 。private String E 。private double score 。private String stdAns 。private String stuAns 。public Question(> public Question(String title, String A, String B, String C, String D, String E, double score, String stdAns, String stuAns> this.title = title 。this.A = A 。this.B = B 。t

3、his.C = C 。this.D = D 。this.E = E 。this.score = score 。this.stdAns = stdAns 。this.stuAns = stuAns 。public String getTitle(> return title 。public void setTitle(String title> this.title = title 。return A 。public void setA(String A> this.A = A 。 public String getB(> return B 。public void se

4、tB(String B> this.B = B 。public String getC(> return C 。public void setC(String C> this.C = C 。public String getD(> return D 。public void setD(String D> this.D = D 。public String getE(> return E 。public void setE(String E> this.E = E 。public double getScore(> return score 。pu

5、blic void setScore(double score> this.score = score 。public String getStdAns(> return stdAns 。public void setStdAns(String stdAns> this.stdAns = stdAns 。public String getStuAns(> return stuAns 。public void setStuAns(String stuAns> this.stuAns = stuAns 。public double check(> return

6、2 。Text paper/* To change this template, choose Tools | Templates* and open the template in the editor.*/package ujn.ise.qsp.entity 。import java.io.Serializable 。import java.util.ArrayList 。/* author Administrator*/public class TestPaper implements Serializable private String title 。private double s

7、core 。private ArrayList<Question> qs 。private int time 。private String teacher 。public TestPaper(> public TestPaper(String title, double score, ArrayList<Question> qs, int time, String teacher> this.title = title 。this.score = score 。this.qs = qs 。this.time = time 。 this.teacher =

8、teacher 。public String getTitle(> return title 。public void setTitle(String title> this.title = title 。public double getScore(> return score 。this.score = score。public ArrayList<Question> getQs(> return qs 。public void setQs(ArrayList<Question> qs> this.qs = qs 。public int

9、 getTime(> return time 。public void setTime(int time> this.time = time 。public String getTeacher(> return teacher 。public void setTeacher(String teacher> this.teacher = teacher 。public double calculateScore(> double sum = 0 。for (Question question : qs> sum += question.check(> 。

10、return sum 。toolkit/* To change this template, choose Tools | Templates* and open the template in the editor.*/package ujn.ise.qsp.toolkit 。import java.io.BufferedReader 。import java.io.File 。import java.io.FileInputStream 。import java.io.FileOutputStream 。import java.io.FileReader 。import java.io.I

11、OException 。import java.io.ObjectInputStream 。import java.io.ObjectOutputStream 。import java.sql.Connection 。import java.sql.DriverManager 。import java.sql.ResultSet 。import java.sql.SQLException 。import java.sql.Statement 。import java.util.ArrayList 。import java.util.logging.Level 。import java.util

12、.logging.Logger 。import ujn.ise.qsp.entity.Question 。import ujn.ise.qsp.entity.TestPaper 。/* author Administrator*/public class Toolkit public static TestPaper generateTestPaper(String url, String user, String password> throws SQLException TestPaper paper = new TestPaper(>。ArrayList<Questio

13、n> qs = new ArrayList<>(> 。Connection conn = DriverManager.getConnection(url, user, password> 。Statement stmt = conn.createStatement(>。String sql = "select * from multiplequestion" 。ResultSet rset = stmt.executeQuery(sql> 。while (rset.next(>> Question q = new Que

14、stion(> 。q.setTitle(rset.getString(1>> 。q.setA(rset.getString(2>> 。q.setB(rset.getString(3>> 。q.setC(rset.getString(4>> 。q.setD(rset.getString(5>> 。q.setE(rset.getString(6>> 。q.setStdAns(rset.getString(7>> 。q.setStuAns(""> 。q.setScore(rset.ge

15、tDouble(8>> 。qs.add(q> 。conn.close(> 。paper.setQs(qs>。return paper 。public static TestPaper generateTestPaper(String fname> throws IOException return generateTestPaper(new File(fname>> 。public static TestPaper generateTestPaper(File file> throws IOException TestPaper paper

16、 = new TestPaper(>。ArrayList<Question> qs = new ArrayList<>(> 。BufferedReader in = new BufferedReader(new FileReader(file>> 。String line = in.readLine(> 。 paper.setTitle(line> 。while (true> line = in.readLine(> 。if (line = null> break 。Question q = new Question

17、(> 。 q.setTitle(line> 。q.setA(in.readLine(>> 。 q.setB(in.readLine(>> 。q.setC(in.readLine(>> 。 q.setD(in.readLine(>> 。q.setE(in.readLine(>> 。 q.setStdAns(in.readLine(>> 。q.setStuAns(""> 。 q.setScore(Double.parseDouble(in.readLine(>>> 。qs

18、.add(q> 。in.close(> 。 paper.setQs(qs>。return paper 。public static boolean saveTestPaper(TestPaper paper, String fname> ObjectOutputStream out = null 。try File file = new File(fname> 。FileOutputStream fout = new FileOutputStream(file> 。out = new ObjectOutputStream(fout> 。 out.wri

19、teObject(paper> 。out.close(> 。 return true 。 catch (IOException ex> Logger.getLogger(Toolkit.class.getName(>>.log(Level.SEVERE, null, ex> 。 return false 。 finally try out.close(> 。 catch (IOException ex> Logger.getLogger(Toolkit.class.getName(>>.log(Level.SEVERE, null,

20、ex> 。public static TestPaper readTestPaper(String fname> throws IOException, ClassNotFoundException return readTestPaper(new File(fname>> 。public static TestPaper readTestPaper(File file> throws IOException, ClassNotFoundException ObjectInputStream in = new ObjectInputStream(new FileI

21、nputStream(file>> 。TestPaper paper = (TestPaper> in.readObject(>。 in.close(> 。return paper 。Eaxm system/* To change this template, choose Tools | Templates* and open the template in the editor.*/。import java.awt.event.ActionEvent 。import java.awt.event.ActionListener 。import java.io.I

22、OException 。import java.util.logging.Level 。import java.util.logging.Logger 。import javax.swing.ImageIcon 。import javax.swing.JOptionPane 。import javax.swing.Timer 。import ujn.ise.qsp.entity.TestPaper 。import ujn.ise.qsp.toolkit.Toolkit 。import ujn.ise.qsp.view.AboutJDialog 。import ujn.ise.qsp.view.

23、ExerciseJDialog 。import ujn.ise.qsp.view.MultipleJDialog 。/* author Administrator*/public class ExamSystem extends javax.swing.JFrame private int time = 90 * 60 。private Timer timer 。private MultipleJDialog mdialog 。private int flag 。private TestPaper paper。private ExerciseJDialog exerdialog 。privat

24、e class MoveTitle extends Thread Overridepublic void run(> int w = jLabelTitle.getWidth(> 。int x = w 。int y = jLabelTitle.getY(> 。while (true> if (x < -w> x = w 。 else x -= 5 。 jLabelTitle.setLocation(x, y> 。 try Thread.sleep(50> 。 catch (InterruptedException ex> Logger.ge

25、tLogger(ExamSystem.class.getName(>>.log(Level.SEVERE, null, ex> 。/* Creates new form ExamSystem*/public ExamSystem(> initComponents(> 。this.setLocationRelativeTo(null> 。timer = new Timer(1000, new ActionListener(> Overridepublic void actionPerformed(ActionEvent e> String time

26、str = String.format("%02d:%02d:%02d", time- / 3600, time % 3600 / 60, time % 60> 。jLabelTime.setText(timestr> 。if (time = 0> > 。flag = 0 。 /* This method is called from within the constructor to initialize the form.* WARNING: Do NOT modify this code. The content of this method

27、is always * regenerated by the Form Editor.*/SuppressWarnings("unchecked">/ <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents(> jToolBar1 = new javax.swing.JToolBar(> 。 jButtonExit = new javax.swing.JButton(> 。jLa

28、bel2 = new javax.swing.JLabel(> 。 jLabelName = new javax.swing.JLabel(> 。 jLabelTime = new javax.swing.JLabel(> 。jLabel5 = new javax.swing.JLabel(> 。 jSeparator2 = new javax.swing.JSeparator(> 。 imageJPanel1 = new ujn.ise.qsp.view.ImageJPanel(> 。jPanel1 = new javax.swing.JPanel(>

29、; 。jLabelTitle = new javax.swing.JLabel(> 。jMenuBar1 = new javax.swing.JMenuBar(> 。jMenu1 = new javax.swing.JMenu(> 。jMenuItemLogin = new javax.swing.JMenuItem(> 。 jMenuItemHandin = new javax.swing.JMenuItem(> 。jSeparator1 = new javax.swing.JPopupMenu.Separator(> 。 jMenuItemExit =

30、new javax.swing.JMenuItem(> 。jMenuMultiple = new javax.swing.JMenu(> 。 jMenuItemMultipleQuestion = new javax.swing.JMenuItem(> 。jMenu3 = new javax.swing.JMenu(> 。jMenuItemExercise = new javax.swing.JMenuItem(> 。jMenuItemAbout = new javax.swing.JMenuItem(> 。 setDefaultCloseOperation

31、(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE> setTitle("Exam System"> 。setIconImage(new ImageIcon("logo.jpg">.getImage(>> 。 addWindowListener(new java.awt.event.WindowAdapter(> public void windowClosing(java.awt.event.WindowEvent evt> formWindowClosing(ev

32、t> 。> 。jToolBar1.setRollover(true> 。 jButtonExit.setText("Exit"> 。 jButtonExit.setFocusable(false> 。 jButtonExit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER> 。 jButtonExit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM> 。 jButtonExit.addActio

33、nListener(new java.awt.event.ActionListener(> public void actionPerformed(java.awt.event.ActionEvent evt> jButtonExitActionPerformed(evt> 。> 。jToolBar1.add(jButtonExit> 。jLabel2.setText(" 考生姓名: "> 。jLabelName.setText("jLabel3"> 。 jLabelTime.setText("00:0

34、0:00"> 。 jLabel5.setText(" 剩余時(shí)間: "> 。newjavax.swing.GroupLayout imageJPanel1Layout = javax.swing.GroupLayout(imageJPanel1> 。imageJPanel1.setLayout(imageJPanel1Layout> 。 imageJPanel1Layout.setHorizontalGroup(imageJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Ali

35、gnment.LEADING> .addGap(0, 496, Short.MAX_V ALUE>> 。 imageJPanel1Layout.setVerticalGroup(imageJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING> .addGap(0, 268, Short.MAX_V ALUE>> 。jPanel1.setLayout(null> 。 jLabelTitle.setBackground(new java.awt.Color(5

36、1, 0, 255>> 。 jLabelTitle.setFont(new java.awt.Font(" 華文行楷 ", 1, 18>> 。 / NOI18N jLabelTitle.setForeground(new java.awt.Color(255, 255, 0>> 。 jLabelTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER> 。 jLabelTitle.setText("Welcome."> 。jLabelTit

37、le.setOpaque(true> 。 jPanel1.add(jLabelTitle> 。jLabelTitle.setBounds(10, 10, 476, 21> 。 jMenu1.setText(" 操作 (O>"> 。jMenu1.addMenuListener(new javax.swing.event.MenuListener(> public void menuCanceled(javax.swing.event.MenuEvent evt> public void menuDeselected(javax.swi

38、ng.event.MenuEvent evt> public void menuSelected(javax.swing.event.MenuEvent evt> jMenu1MenuSelected(evt> 。 > 。jMenuItemLogin.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent. VK_L, java.awt.event.InputEvent.CTRL_MASK>> 。jMenuItemLogin.setText("Login&q

39、uot;> 。 jMenuItemLogin.addActionListener(new java.awt.event.ActionListener(> public void actionPerformed(java.awt.event.ActionEvent evt> jMenuItemLoginActionPerformed(evt> 。 > 。jMenu1.add(jMenuItemLogin> 。 jMenuItemHandin.setText("Hand In"> 。 jMenuItemHandin.addActionL

40、istener(new java.awt.event.ActionListener(> public void actionPerformed(java.awt.event.ActionEvent evt> jMenuItemHandinActionPerformed(evt> 。> 。jMenu1.add(jMenuItemHandin> 。 jMenu1.add(jSeparator1> 。jMenuItemExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyE

41、vent.V K_X, java.awt.event.InputEvent.ALT_MASK>> 。jMenuItemExit.setText("Exit"> 。 jMenuItemExit.addActionListener(new java.awt.event.ActionListener(> public void actionPerformed(java.awt.event.ActionEvent evt> jMenuItemExitActionPerformed(evt> 。> 。jMenu1.add(jMenuItemE

42、xit> 。 jMenuBar1.add(jMenu1> 。 jMenuMultiple.setText(" 測試 "> 。 jMenuMultiple.addMenuListener(new javax.swing.event.MenuListener(> public void menuCanceled(javax.swing.event.MenuEvent evt> public void menuDeselected(javax.swing.event.MenuEvent evt> public void menuSelected

43、(javax.swing.event.MenuEvent evt> jMenuMultipleMenuSelected(evt> 。> 。jMenuItemMultipleQuestion.setText(" 多選題 ."> 。 jMenuItemMultipleQuestion.addActionListener(new java.awt.event.ActionListener(> public void actionPerformed(java.awt.event.ActionEvent evt> jMenuItemMultiple

44、QuestionActionPerformed(evt> 。> 。 jMenuMultiple.add(jMenuItemMultipleQuestion> 。 jMenuBar1.add(jMenuMultiple> 。 jMenu3.setText("Help"> 。jMenuItemExercise.setText(" 演算紙 "> 。 jMenuItemExercise.addActionListener(new java.awt.event.ActionListener(> public void ac

45、tionPerformed(java.awt.event.ActionEvent evt> jMenuItemExerciseActionPerformed(evt> 。> 。 jMenu3.add(jMenuItemExercise> 。 jMenuItemAbout.setText("About"> 。 jMenuItemAbout.addActionListener(new java.awt.event.ActionListener(> public void actionPerformed(java.awt.event.Actio

46、nEvent evt> jMenuItemAboutActionPerformed(evt> 。 > 。 jMenu3.add(jMenuItemAbout> 。 jMenuBar1.add(jMenu3> 。 setJMenuBar(jMenuBar1> 。 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane(>> 。 getContentPane(>.setLayout(layout> 。 layout.setHorizontalG

47、roup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING> .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_V ALUE>.addGroup(layout.createSequentialGroup(> .addComponent(jLabel2> .addPreferredGap(javax.swing.La

48、youtStyle.ComponentPlacement.RELATED> .addComponent(jLabelName, javax.swing.GroupLayout.PREFERRED_SIZE,91,javax.swing.GroupLayout.PREFERRED_SIZE>.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,245,Short.MAX_VALUE>.addComponent(jLabel5> .addPreferredGap(javax.swing.Lay

49、outStyle.ComponentPlacement.RELATED> .addComponent(jLabelTime>>.addComponent(jSeparator2> .addGroup(layout.createSequentialGroup(>>.addComponent(imageJPanel1,javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_V ALUE>.addComponent(jPanel1,javax.s

50、wing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_V ALUE>>.addContainerGap(>>> 。 layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING> .addGroup(layout.createSequentialGroup(>.addComponent(jToolBar1, javax.swin

51、g.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE>.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED>.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE>.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED

52、>.addComponent(imageJPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE>.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED>.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swin

53、g.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE>.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED>.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN E>.addComponent(jLabel2>.addComponent(jLabelName>.addComponent(jLabelTi

54、me> .addComponent(jLabel5>>>> 。pack(> 。/ </editor-fold>private void jMenuItemExitActionPerformed(java.awt.event.ActionEvent evt> exit(> 。private void jButtonExitActionPerformed(java.awt.event.ActionEvent evt> exit(> 。private void formWindowClosing(java.awt.event.W

55、indowEvent evt> exit(> 。private void jMenuItemAboutActionPerformed(java.awt.event.ActionEvent evt> AboutJDialog about = new AboutJDialog(this, true> 。 about.setVisible(true> 。private void jMenuItemLoginActionPerformed(java.awt.event.ActionEvent evt> String name = JOptionPane.showIn

56、putDialog(this, "Please input your name:"> 。if (name = null | name.equals("">> return 。this.jLabelName.setText(name> 。try paper = Toolkit.generateTestPaper("paper.txt"> 。 catch (IOException ex> Logger.getLogger(ExamSystem.class.getName(>>.log(Lev

57、el.SEVERE, null, ex> 。 return 。this.jLabelTitle.setText(paper.getTitle(>> 。new MoveTitle(>.start(> 。 timer.start(> 。flag = 1 。private void jMenuItemMultipleQuestionActionPerformed(java.awt.event.ActionEvent evt> if (mdialog = null> mdialog = new MultipleJDialog(this, true, pa

58、per.getQs(>> 。 mdialog.setVisible(true> 。private void jMenuItemHandinActionPerformed(java.awt.event.ActionEvent evt> double score = paper.calculateScore(> 。JOptionPane.showMessageDialog(this, score> 。flag = 2 。private void jMenu1MenuSelected(javax.swing.event.MenuEvent evt> this

59、.jMenuItemLogin.setEnabled(flag = 0 | flag = 2> 。 this.jMenuItemHandin.setEnabled(flag = 1> 。private void jMenuMultipleMenuSelected(javax.swing.event.MenuEvent evt> this.jMenuItemMultipleQuestion.setEnabled(flag = 1> 。private void jMenuItemExerciseActionPerformed(java.awt.event.ActionEve

60、nt evt> if (exerdialog = null> exerdialog = new ExerciseJDialog(this, false> 。 exerdialog.setVisible(true> 。/* param args the command line arguments*/public static void main(String args> /* Set the Nimbus look and feel */<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional> "> /* If Nimbus (introduced in Java SE 6> is not available, stay with the default look and feel. * For details see*/try for (javax.swing.UIManager.LookAndFeelInfo

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論