Advertisement
pastetumlum

questionpanel

Jul 14th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. package view;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.GridBagConstraints;
  8. import java.awt.GridBagLayout;
  9. import java.awt.GridLayout;
  10. import java.awt.Insets;
  11. import java.awt.Label;
  12. import java.awt.TextArea;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15. import java.util.ArrayList;
  16.  
  17. import javax.swing.BorderFactory;
  18. import javax.swing.BoxLayout;
  19. import javax.swing.JButton;
  20. import javax.swing.JFrame;
  21. import javax.swing.JLabel;
  22. import javax.swing.JOptionPane;
  23. import javax.swing.JPanel;
  24. import javax.swing.JTextArea;
  25.  
  26. import model.QuestionLibrary;
  27.  
  28. public class QuestionPanel extends JPanel {
  29.     private JTextArea taQuestion;
  30.     private CustomButton btA, btB, btC, btD;
  31.     private QuestionLibrary library;
  32.  
  33.     private JPanel questionPanel, answerPanel;
  34.  
  35.     public QuestionPanel() {
  36.         setPreferredSize(new Dimension(360, 200));
  37.         setBorder(BorderFactory.createTitledBorder("Question"));
  38.         // init components
  39.         taQuestion = new JTextArea(10, 30);
  40.         taQuestion.setMargin(new Insets(10, 10, 10, 10));
  41.         taQuestion.setLineWrap(true);
  42.         taQuestion.setWrapStyleWord(true);
  43.         taQuestion.setEditable(false);
  44.         taQuestion.setText("Question Placeholder");
  45.         taQuestion.setFocusable(false);
  46.         btA = new CustomButton("a", "Answer Placeholder");
  47.         btB = new CustomButton("b", "Answer Placeholder");
  48.         btC = new CustomButton("c", "Answer Placeholder");
  49.         btD = new CustomButton("d", "Answer Placeholder");
  50.         setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  51.         questionPanel = new JPanel();
  52.         add(questionPanel);
  53.         questionPanel.add(taQuestion);
  54.         answerPanel = new JPanel();
  55.         add(answerPanel);
  56.         GridLayout layout = new GridLayout(0, 2);
  57.         layout.setHgap(5);
  58.         layout.setVgap(5);
  59.         answerPanel.setLayout(layout);
  60.         answerPanel.add(btA);
  61.         answerPanel.add(btB);
  62.         answerPanel.add(btC);
  63.         answerPanel.add(btD);
  64.         setVisible(false);
  65.     }
  66.  
  67.     public void updateQuestion() {
  68.         String content = library.getQuestions().get(library.getQuestionIndex()).getContent();
  69.         String a = library.getQuestions().get(library.getQuestionIndex()).getAnswerA();
  70.         String b = library.getQuestions().get(library.getQuestionIndex()).getAnswerB();
  71.         String c = library.getQuestions().get(library.getQuestionIndex()).getAnswerC();
  72.         String d = library.getQuestions().get(library.getQuestionIndex()).getAnswerD();
  73.         taQuestion.setText(content);
  74.         btA.setText(a);
  75.         btB.setText(b);
  76.         btC.setText(c);
  77.         btD.setText(d);
  78.     }
  79.  
  80.     public CustomButton getBtA() {
  81.         return btA;
  82.     }
  83.  
  84.     public CustomButton getBtB() {
  85.         return btB;
  86.     }
  87.  
  88.     public CustomButton getBtC() {
  89.         return btC;
  90.     }
  91.  
  92.     public CustomButton getBtD() {
  93.         return btD;
  94.     }
  95.  
  96.     public void setLibrary(QuestionLibrary library) {
  97.         this.library = library;
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement