1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| package tn.esen.gui.candidat;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.persistence.IdClass;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import tn.esen.delegate.GestionCandidatDelegate;
import tn.esen.delegate.GestionTestDelegate;
import tn.esen.entities.Candidat;
import tn.esen.entities.Question;
import tn.esen.entities.Reponse;
import tn.esen.entities.Test;
import tn.esen.gui.authentification.Authentification;
import java.awt.Window.Type;
import java.util.ArrayList;
import java.util.List;
import java.awt.Toolkit;
import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class EspaceCandidat extends JFrame {
private JPanel contentPane;
static int idCandidat;
int note=0;
boolean clicked=false;
boolean clickedFalse=false;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
EspaceCandidat frame = new EspaceCandidat();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public EspaceCandidat() {
setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Daly\\Desktop\\logo_businessdecision.png"));
setTitle(" Espace du candidat");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JPanel panel = new JPanel();
contentPane.add(panel, BorderLayout.CENTER);
panel.setLayout(null);
idCandidat = Authentification.idCandidat;
//System.out.println(Authentification.idCandidat);
Candidat candidat = GestionCandidatDelegate.doFindCandidatById(idCandidat);
List<Test> tests = GestionTestDelegate.doFindAllTestByCandidat(candidat);
Test test = tests.get(0);
List<Question> questions= (List<Question>) test.getQuestions();
int j=0;
int k=1;
List<Reponse> reponses= new ArrayList<Reponse>();
for (int i = 0; i < questions.size(); i++) {
JLabel lbl= new JLabel("Question "+k);
k++;
JLabel lblContenu = new JLabel(questions.get(i).getContenu());
reponses = (List<Reponse>) questions.get(i).getReponses();
lbl.setBounds(0, j, 130, 14);
j=j+30;
lblContenu.setBounds(0,j,500, 14);
j=j+30;
panel.add(lbl);
panel.add(lblContenu);
ButtonGroup bG1 = new ButtonGroup();
for (Reponse reponse : reponses) {
JRadioButton rdbtnNewRadioButton = new JRadioButton(reponse.getContenu()); /*Tout le code ci dessus est fait pour que les radio boutton des reponses et les questions seront visible de maniére dynamique car on connait pas le nombre exacte de question dans un test ni le nombre des reponses*/
rdbtnNewRadioButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
if(reponse.isEtat() ){
note++;
System.out.println(note);
clicked=true;
clickedFalse=false; /*cette variable est faite par ce que si le candidat coche 5 fois la bonne réponses il aura 5 points or moi je veux qu'il reçoit seuelemnt 1 point pour sa bonne réponse*/
}
else if(reponse.isEtat()==false ){
if(note>0 && clickedFalse==false){
note--;
System.out.println(note);
}
clicked=false;
clickedFalse=true;
}
}
});
bG1.add(rdbtnNewRadioButton);
rdbtnNewRadioButton.setBounds(50, j, 500, 14);
j+=30;
panel.add(rdbtnNewRadioButton);
}
}
JButton btnNewButton = new JButton("Valider");
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
System.out.println(note);
}
});
btnNewButton.setBounds(85, j+100, 89, 23);
panel.add(btnNewButton);
}
} |
Partager