Esempio n. 1
0
 @Override
 public void setUpQuestion(QuestionMapPack qmp) {
   // TODO
   questionMap = qmp.getQmp();
   System.out.println("收到的questionPack的大小为" + questionMap.size());
   ArrayList<Long> queId = new ArrayList<Long>(questionMap.keySet()); // all question's id
   for (long l : queId) {
     Question temQ = questionMap.get(l);
     String field = temQ.getField();
     if (!fields.contains(field)) {
       fields.add(field);
     }
     questionList.put(temQ.getTitle(), temQ.getQuestionId());
   }
   for (String s : fields) {
     DefaultMutableTreeNode dmtn = new DefaultMutableTreeNode(s);
     if (!tree.containsKey(s)) {
       tree.put(s, dmtn);
       top.add(dmtn);
     }
   }
   for (long l : queId) {
     Question tempQuestion = questionMap.get(l);
     String field = tempQuestion.getField();
     DefaultMutableTreeNode dmtn = tree.get(field);
     if (!addedQuestion.contains(tempQuestion)) {
       System.out.println("添加了一次");
       dmtn.add(new DefaultMutableTreeNode(tempQuestion.getTitle()));
       addedQuestion.add(tempQuestion);
     }
   }
   repaint();
 }
Esempio n. 2
0
 private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) throws IOException {
   // TODO 发送已经编辑好的question
   int SendComfirm;
   SendComfirm =
       JOptionPane.showConfirmDialog(null, "确认上传问题?", "提示", JOptionPane.YES_NO_CANCEL_OPTION);
   if (SendComfirm == 0) {
     if (editQuestion) {
       cm.sendOutPack(
           new OrderPack(OrderPack.DELETQUESTION, user.getUserNumber(), "" + selectQuestionId));
       DefaultMutableTreeNode node =
           (DefaultMutableTreeNode) jTree2.getLastSelectedPathComponent();
       String title = (String) node.getUserObject();
       System.out.println("你选择了:" + title.toString());
       Long num = questionList.get(title);
       selectQuestionId = num;
       Question q = questionMap.get(num);
       Question questionToSend =
           new Question(
               jTextField1.getText(),
               q.getField(),
               new StringBuffer(jEditorPane1.getText()),
               user.getUserNumber());
       cm.sendOutPack(questionToSend);
       questionList.remove(questionToSend.getTitle());
       addedQuestion.remove(questionToSend);
       questionMap.remove(questionToSend.getQuestionId());
       jTree2.removeAll();
       cm.sendOutPack(new OrderPack(0, user.getUserNumber(), "byauthor"));
       jTree2.repaint();
     } else {
       Question questionToSend =
           new Question(
               jTextField1.getText(),
               jComboBox1.getSelectedItem().toString(),
               new StringBuffer(jEditorPane1.getText()),
               user.getUserNumber());
       cm.sendOutPack(questionToSend);
     }
   }
   jTree2.setEnabled(true);
   jButton5.setText("Comfirm");
   jButton3.setEnabled(true);
   jButton5.setEnabled(false);
 }