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
|
public class panelsondesonore extends JPanel implements ActionListener
{
//****************Initialisation*******************//
private framesondesonore fenetre = null;
private JLabel TexteQuestion;
private String[] TableauQuestions = new String[10];
private String[] TableauReponses = new String[4];
private JFrame fene;
private String reponse;
private String id, SondageActif;
private int temp;
//************Constructeur*************************//
public panelsondesonore(framesondesonore fenetre, int numero, String user)
{
temp=numero;
this.fenetre = fenetre;
fene = fenetre;
setLayout(new GridBagLayout());
id=user;
// On recherche le sondage actif à la date actuelle
SondageActif = modelesondesonore.sondageactif();
// On recherche les questions correspondantes
TableauQuestions = modelesondesonore.getQuestion(SondageActif);
TableauReponses = modelesondesonore.getReponse(TableauQuestions[numero]);
// gbc sera la contrainte du GridBagLayout
GridBagConstraints gbc = new GridBagConstraints();
//Affichage de la question
TexteQuestion = new JLabel (TableauQuestions[numero]);
gbc.anchor = GridBagConstraints.NORTH;
gbc.insets = new Insets(5,0,5,0);
gbc.gridwidth = GridBagConstraints.REMAINDER;
TexteQuestion.setFont(new Font("Times-Roman",Font.BOLD,20));
add(TexteQuestion,gbc);
//Bouton rep1
JButton rep1 = new JButton("rep1");
gbc.anchor = GridBagConstraints.WEST;
rep1.setBackground(Color.WHITE);
gbc.insets = new Insets(30,5,30,5);
gbc.gridwidth = 1;
add(rep1,gbc);
//Si c'est la première question du sondage
if(numero==0)
{
//Lecture du fichier audio indiquant le n° de la question
String NUM="NUM";
int var=numero+1;
NUM=NUM+var;
sound.lecture("./Sons/"+NUM+".wav");
//Lecture question
String s = modelesondesonore.getSon(TableauQuestions[numero]);
sound.lecture("./Sons/"+s+"");
}
//***********************Gestion des actions***********************//
rep1.addActionListener((new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
//On stocke la valeur de la réponse pour la requête
reponse=TableauReponses[0];
// On enregistre la réponse dans la BDD
int sondageactif = Integer.parseInt(SondageActif);
modelesondesonore.SauvegardeReponse(id,sondageactif,reponse,temp+1);
//Si on n'est pas à la dernière question
if (temp !=9)
{
//Passage à la question suivante
temp++;
controllersondesonore.suivant(TableauQuestions[temp],TexteQuestion,temp,fene,id);
}
//sinon on arrête le sondage
else
{
fene.dispose();
JFrame fenetreerreur = new framemessage("Sondage terminé !");
fenetreerreur.show();
}
}
}));
} |
Partager