📄 studentframe.java
字号:
unfinishitem--; break; } System.out.println("item index----"+randomindex); } ItemInfo radomiteminfo=iteminfo[randomindex]; String radomitemtype=radomiteminfo.getItemtype(); centerpanel.removeAll(); if("单选题".equals(radomitemtype)) centerpanel.add(new singleChoiceJPanel(radomiteminfo)); else if("多选题".equals(radomitemtype)) centerpanel.add(new multipleChoiceJPanel(radomiteminfo)); else if("对错题".equals(radomitemtype)) centerpanel.add(new TrueFalseJPanel(radomiteminfo)); else if("填空题".equals(radomitemtype)) centerpanel.add(new FillBlankJPanel(radomiteminfo)); else if("简答题".equals(radomitemtype)) centerpanel.add(new BriefAnswerJPanel(radomiteminfo)); else System.out.println("无此题型"); centerpanel.validate(); } else{ centerpanel.removeAll(); centerpanel.validate(); mainPanel.removeAll(); mainPanel.add(new JLabel(" 你已经完成测试,你本次的测试成绩为 "+testscore),BorderLayout.CENTER); mainPanel.validate(); } } private void initGUI() { try { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setTitle("\u8054\u673a\u6d4b\u8bd5\u7cfb\u7edf"); this.setResizable(false); getContentPane().setLayout(null); { studentToolBar = new JToolBar(); getContentPane().add(studentToolBar); studentToolBar.setBounds(0, 2, 100, 26); { starttestButton = new JButton(new ImageIcon("images/onlinetest.gif")); studentToolBar.add(starttestButton); starttestButton.setToolTipText("\u8bd5\u9898\u6d4b\u8bd5"); starttestButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { starttestButtonActionPerformed(evt); } }); } { scoreAccountButton = new JButton(new ImageIcon("images/Account.gif")); studentToolBar.add(scoreAccountButton); scoreAccountButton.setToolTipText("\u6210\u7ee9\u7edf\u8ba1"); scoreAccountButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { scoreAccountButtonActionPerformed(evt); } }); } { reconnectButton = new JButton(new ImageIcon("images/reconnect.gif")); studentToolBar.add(reconnectButton); reconnectButton.setToolTipText("重新连接服务器"); reconnectButton.setEnabled(false); reconnectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { reconnectButtonActionPerformed(evt); } }); } } { jScrollPane1 = new JScrollPane(); getContentPane().add(jScrollPane1); jScrollPane1.setBounds(0, 34, 623, 419); { mainPanel = new JPanel(); jScrollPane1.setViewportView(mainPanel); mainPanel.setPreferredSize(new java.awt.Dimension(620, 406)); } } { studentMenuBar = new JMenuBar(); setJMenuBar(studentMenuBar); { jMenu1 = new JMenu(); studentMenuBar.add(jMenu1); jMenu1.setText("\u6587\u4ef6"); { starttestMenuItem = new JMenuItem(); jMenu1.add(starttestMenuItem); starttestMenuItem.setText("试题测试"); starttestMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { starttestButtonActionPerformed(evt); } }); } { scoreAccountMenuItem = new JMenuItem(); jMenu1.add(scoreAccountMenuItem); scoreAccountMenuItem.setText("\u6210\u7ee9\u7edf\u8ba1"); scoreAccountMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { scoreAccountButtonActionPerformed(evt); } }); } { reconnectMenuItem = new JMenuItem(); jMenu1.add(reconnectMenuItem); reconnectMenuItem.setText("\u91cd\u65b0\u8fde\u63a5"); reconnectMenuItem.setEnabled(false); reconnectMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { reconnectButtonActionPerformed(evt); } }); } { exitMenuItem = new JMenuItem(); jMenu1.add(exitMenuItem); exitMenuItem.setText("\u9000\u51fa"); exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { exitMenuItemActionPerformed(evt); } }); } } { aboutMenu = new JMenu(); studentMenuBar.add(aboutMenu); aboutMenu.setText("\u5173\u4e8e"); { helpMenuItem = new JMenuItem(); aboutMenu.add(helpMenuItem); helpMenuItem.setText("\u5e2e\u52a9"); helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { mainPanel.removeAll(); mainPanel.add(new AboutJPanel(),BorderLayout.CENTER); mainPanel.validate(); } }); } } { centerpanel=new JPanel(); titlepanel=new JPanel(); titlepanel.add(new JLabel("科目")); subjectcombobox = new JComboBox(); titlepanel.add(subjectcombobox); titlepanel.add(new JLabel("难度系数")); difficulttfone=new JTextField(); difficulttfone.setText("0 "); titlepanel.add(difficulttfone); titlepanel.add(new JLabel("到")); difficulttftwo=new JTextField(); difficulttftwo.setText("1 "); titlepanel.add(difficulttftwo); submitbt=new JButton("提交"); titlepanel.add(submitbt); submitbt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String subjectstr=subjectcombobox.getSelectedItem().toString(); float difone=0; float diftwo=1; try { difone=Float.parseFloat(difficulttfone.getText()); diftwo=Float.parseFloat(difficulttftwo.getText()); if(difone>1||difone<0||diftwo<0||diftwo>1){ JOptionPane.showMessageDialog(null,"难度系数为0-1的小数","错误",JOptionPane.ERROR_MESSAGE); return; } if(difone>diftwo){ float tempdif=difone; difone=diftwo; diftwo=tempdif; } } catch(Exception ex) { // only allow integer values Toolkit.getDefaultToolkit().beep(); JOptionPane.showMessageDialog(null,"难度系数为0-1的小数","错误",JOptionPane.ERROR_MESSAGE); return; } testscore=0; submitbt.setEnabled(false); String msg="GETQA:"; if("全部".equals(subjectstr)) msg=msg+"select * from item_info where difficulty>="+difone+" and difficulty<="+diftwo; else msg=msg+"select * from item_info where difficulty>="+difone+" and difficulty<="+diftwo+" and subject='"+subjectstr+"'"; msg=new String(msg.getBytes()); pswriter.println(msg); pswriter.flush(); String QAstrinfo=null; try { QAstrinfo=bufreader.readLine(); String[] QAstrarray=QAstrinfo.split("@_@"); if("QA".equals(QAstrarray[0])){ itemsnumber=QAstrarray.length-1; unfinishitem=itemsnumber; iteminfo=new ItemInfo[itemsnumber]; itemstate=new int[itemsnumber]; if(QAstrarray.length>1){ for(int i=1;i<QAstrarray.length;i++){ System.out.println(QAstrarray[i]); String[] QAarray=QAstrarray[i].split("&_&"); int itemid=Integer.parseInt(QAarray[0]); String itemtype=QAarray[1]; String content=QAarray[2]; String answer=QAarray[3]; int score=Integer.parseInt(QAarray[4]); int limittime=Integer.parseInt(QAarray[5]); String subject=QAarray[6]; float difficulty=Float.parseFloat(QAarray[7]); iteminfo[i-1]=new ItemInfo(itemid,itemtype,content,answer,score,limittime,subject,difficulty); itemstate[i-1]=1; } NextItem(); } else { JOptionPane.showMessageDialog(null,"无该条件下的试题,请重新选择测试条件","联机测试系统",JOptionPane.ERROR_MESSAGE); submitbt.setEnabled(true); } } else { JOptionPane.showMessageDialog(null,"试题获取失败","联机测试系统",JOptionPane.ERROR_MESSAGE); submitbt.setEnabled(true); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); JOptionPane.showMessageDialog(null,"IO异常,请重新连接","联机测试系统",JOptionPane.ERROR_MESSAGE); submitbt.setEnabled(true); reconnectButton.setEnabled(true); reconnectMenuItem.setEnabled(true); } if(QAstrinfo==null){ JOptionPane.showMessageDialog(null,"与服务器的连接已经中断,请重新连接","联机测试系统",JOptionPane.ERROR_MESSAGE); reconnectButton.setEnabled(true); reconnectMenuItem.setEnabled(true); return ; } } }); } } pack(); this.setSize(631, 514); } catch (Exception e) { e.printStackTrace(); } }}class FloatDocument extends PlainDocument { public void insertString(int offset, String s, AttributeSet attributeSet) throws BadLocationException { try { Float.parseFloat(s); } catch(Exception ex) { // only allow integer values Toolkit.getDefaultToolkit().beep(); JOptionPane.showMessageDialog(null,"难度系数为0-1的小数","错误",JOptionPane.ERROR_MESSAGE); return; } super.insertString(offset, s, attributeSet); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -