if(Source ==(j2.Jouer)){ this.setVisible(false); jeu2.setVisible(true); // j'ajoute la Q1 int compt=0; comp++; jeu2.jeu.test1.setText(" Q1:"+j1.list1.get(0)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(0)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(0)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(0)); }if(Source ==jeu2.buttonrep.button1){ for(int i=1;i<n;i++){ //Si Q1 vrai if(comp==1){ comp++; compteur=compteur+1; jeu2.jeupanel.Score1.setText(resultat); //Ajoute Q2 jeu2.jeu.test1.setText(" Q2:"+j1.list1.get(i)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(i)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(i)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(i)); break; } if(comp==2){ comp++; compteur=compteur+1; jeu2.jeupanel.Score1.setText(resultat); //Ajoute Q2 jeu2.jeu.test1.setText(" Q3:"+j1.list1.get(i)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(i)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(i)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(i)); break; } if(comp==3){ comp++; compteur=compteur+1; jeu2.jeupanel.Score1.setText(resultat); //Ajoute Q2 jeu2.jeu.test1.setText(" Q4:"+j1.list1.get(i)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(i)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(i)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(i)); break; } if(comp==4){ comp++; compteur=compteur+1; jeu2.jeupanel.Score1.setText(resultat); //Ajoute Q2 jeu2.jeu.test1.setText(" Q5:"+j1.list1.get(i)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(i)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(i)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(i)); break; } }
if(Source.equals(j2.Suivant2)){ j2.cmp++; j2.list1.add(j1.question1.getText()); j2.list2.add(j1.repcorrect1.getText()); j2.list3.add(j1.repincorrect11.getText()); j2.list4.add(j1.repincorrect22.getText()); j2.question1.setText(t); j2.repcorrect1.setText(t); j2.repincorrect11.setText(t); j2.repincorrect22.setText(t); if(j2.cmp==5){ j2.Suivant2.setEnabled(false); j2.Jouer.setEnabled(true); } } if(Source.equals(j2.Jouer)){ this.setVisible(false); jeu2.setVisible(true); // j'ajoute la Q1 jeu2.jeu.test1.setText(" Q1:"+j1.list1.get(0)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(0)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(0)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(0)); }if(Source ==jeu2.buttonrep.button1){ //Si Q1 vrai compteur=compteur+1; jeu2.jeupanel.Score1.setText(resultat); //Ajoute Q2 jeu2.jeu.test1.setText(" Q2:"+j1.list1.get(1)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(1)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(1)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(1)); }else if(Source ==jeu2.buttonrep.button2 ||Source ==jeu2.buttonrep.button3 ){ //Si Q1 fausse jeu2.jeupanel.Score1.setText(resultat); //J'ajoute Q2 System.out.println("3"); jeu2.jeu.test1.setText(" Q2:"+j1.list1.get(1)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(1)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(1)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(1));} else if(Source ==jeu2.buttonrep.button1){ //Si Q2 vrai compteur=compteur+1; jeu2.jeupanel.Score1.setText(resultat); //Ajoute Q3 jeu2.jeu.test1.setText(" Q3:"+j1.list1.get(2)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(2)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(2)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(2)); }else if(Source ==jeu2.buttonrep.button2 ||Source ==jeu2.buttonrep.button3 ){ //Si Q2 fausse jeu2.jeupanel.Score1.setText(resultat); //Ajoute Q3 jeu2.jeu.test1.setText(" Q3:"+j1.list1.get(3)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(3)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(3)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(3)); }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionimport java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class Jeu extends JFrame implements ActionListener{ Jeuborder2 jborder1= new Jeuborder2(); Jeuborder1 jborder2=new Jeuborder1(); JPanel panel=new JPanel(); Jeu2 jeu2=new Jeu2(); QuestionJ1 j1=new QuestionJ1(); QuestionJ2 j2=new QuestionJ2(); int compteur=0; public Jeu(){ j1.Suivant.addActionListener(this); j2.Suivant2.addActionListener(this); j2.Jouer.addActionListener(this); jeu2.buttonrep.button1.addActionListener(this); jeu2.buttonrep.button2.addActionListener(this); jeu2.buttonrep.button3.addActionListener(this); jeu2.setVisible(false); panel.add(jborder1); panel.add(jborder2); jborder2.setVisible(false); panel.add(j1); panel.add(j2); j2.setVisible(false); this.setSize(400,300); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setContentPane(panel); this.setResizable(false); this.setVisible(true); } public void actionPerformed(ActionEvent e) { Object Source =e.getSource(); String t=""; String resultat=String.valueOf(compteur); if(Source==j1.Suivant){ j1.cmp++; j1.list1.add(j1.question1.getText()); j1.list2.add(j1.repcorrect1.getText()); j1.list3.add(j1.repincorrect11.getText()); j1.list4.add(j1.repincorrect22.getText()); j1.question1.setText(t); j1.repcorrect1.setText(t); j1.repincorrect11.setText(t); j1.repincorrect22.setText(t); if(j1.cmp==5){ jborder1.setVisible(false); jborder2.setVisible(true); j1.setVisible(false); j2.setVisible(true); } } if(Source==j2.Suivant2){ j2.cmp++; j2.list1.add(j1.question1.getText()); j2.list2.add(j1.repcorrect1.getText()); j2.list3.add(j1.repincorrect11.getText()); j2.list4.add(j1.repincorrect22.getText()); j2.question1.setText(t); j2.repcorrect1.setText(t); j2.repincorrect11.setText(t); j2.repincorrect22.setText(t); if(j2.cmp==5){ j2.Suivant2.setEnabled(false); j2.Jouer.setEnabled(true); } } if(Source ==(j2.Jouer)){ this.setVisible(false); jeu2.setVisible(true); // j'ajoute la Q1 jeu2.jeu.test1.setText(" Q1:"+j1.list1.get(0)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(0)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(0)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(0)); }if(Source ==jeu2.buttonrep.button1){ //Si Q1 vrai compteur=compteur+1; jeu2.jeupanel.Score1.setText(resultat); //Ajoute Q2 jeu2.jeu.test1.setText(" Q2:"+j1.list1.get(1)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(1)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(1)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(1)); }else if(Source ==jeu2.buttonrep.button2 ||Source ==jeu2.buttonrep.button3 ){ //Si Q1 fausse jeu2.jeupanel.Score1.setText(resultat); //J'ajoute Q2 System.out.println("3"); jeu2.jeu.test1.setText(" Q2:"+j1.list1.get(1)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(1)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(1)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(1));} else if(Source ==jeu2.buttonrep.button1){ //Si Q2 vrai compteur=compteur+1; jeu2.jeupanel.Score1.setText(resultat); //Ajoute Q3 jeu2.jeu.test1.setText(" Q3:"+j1.list1.get(2)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(2)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(2)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(2)); }else if(Source ==jeu2.buttonrep.button2 ||Source ==jeu2.buttonrep.button3 ){ //Si Q2 fausse jeu2.jeupanel.Score1.setText(resultat); //Ajoute Q3 jeu2.jeu.test1.setText(" Q3:"+j1.list1.get(3)); jeu2.buttonrep.button1.setText("Rep1: "+j1.list2.get(3)); jeu2.buttonrep.button2.setText("Rep2: "+j1.list3.get(3)); jeu2.buttonrep.button3.setText("Rep3: "+j1.list4.get(3)); } }}