A voir également:
- Fonction random
- Fonction si et - Guide
- Fonction moyenne excel - Guide
- Fonction somme excel - Guide
- Fonction trier excel - Guide
- Fonction couleur excel - Guide
5 réponses
nicocorico
Messages postés
799
Date d'inscription
dimanche 19 juin 2011
Statut
Membre
Dernière intervention
3 juillet 2018
138
25 juil. 2011 à 17:35
25 juil. 2011 à 17:35
Quel est ton problème ?
La fonction random est très simple, tu as juste à appeler Radomize pour réinitialiser et random avec la valeur maximale qu'elle doit renvoyer...
La fonction random est très simple, tu as juste à appeler Radomize pour réinitialiser et random avec la valeur maximale qu'elle doit renvoyer...
en fait g suis en trai de coder un jeu de qcm dans lequel les quqtions sont appelé par serie de 4 et je veut le faire de maniere aleatoire
nicocorico
Messages postés
799
Date d'inscription
dimanche 19 juin 2011
Statut
Membre
Dernière intervention
3 juillet 2018
138
25 juil. 2011 à 18:19
25 juil. 2011 à 18:19
Précise où tu bloques, car comme je te le disais il n'y a pas de difficultée particulière avec la fonction Random...
bon voila je definit le random ici
//protected static int hasard = (int)(Math.random()*14);
puis lorsque j'essai d'utiliser la fonction hazard un peu plus bas
question = questions[hasard];
* c1 = A[hasard];
* c2 = B[hasard];
* c3 = C[hasard];
* c4 = D[hasard];
on me signale des erreurs la ou j'ai mis les* coe solution eclipse me ^propose de changer c1.......c4 en string
//protected static int hasard = (int)(Math.random()*14);
puis lorsque j'essai d'utiliser la fonction hazard un peu plus bas
question = questions[hasard];
* c1 = A[hasard];
* c2 = B[hasard];
* c3 = C[hasard];
* c4 = D[hasard];
on me signale des erreurs la ou j'ai mis les* coe solution eclipse me ^propose de changer c1.......c4 en string
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
en fait voici le code complet je met ds asterix partout ou il ya des erreurs
public class Test extends JFrame implements ActionListener{ {
private JPanel pan = new JPanel();
private PanneauQuestionPhysique panneauQuestionPhysique1 = new PanneauQuestionPhysique();
protected static int hasard = (int)(Math.random()*14);
protected static Color vert = new Color(34,139,34);
protected static Color lightcyan = new Color(176,196,222);
protected static Color skyblue = new Color(0,191,255);
protected static Color turquoise = new Color(0,206,209);
protected static Color olive = new Color(202,255,112);
protected static boutonRejouer jButton1 = new boutonRejouer();
protected static b0 jButton2 = new b0(lightcyan);
protected static b12 jButton8 = new b12(skyblue);
protected static b16 jButton10 = new b16(Color.CYAN);
protected static b18 jButton11 = new b18(turquoise);
protected static b20 jButton12 = new b20(olive);
protected static b20 jButton13 = new b20(lightcyan);
private PanneauPlateau panneauPlateau = new PanneauPlateau();
protected static PanneauDe panDe = new PanneauDe();
private PanneauTest Panneau = new PanneauTest();
private void jbInit() throws Exception {
this.setSize(new Dimension(1000, 600));
Panneau.setLayout(null);
this.setContentPane(Panneau);
Panneau.add(panneauPlateau, null);
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jButton2, null);
this.getContentPane().add(jButton8, null);
this.getContentPane().add(jButton10, null);
this.getContentPane().add(jButton12, null);
this.getContentPane().add(jButton13, null);
jButton1.setBounds(new Rectangle(880,80,100,20));
jButton2.setBounds(new Rectangle(880,105,100,20));
jButton8.setBounds(new Rectangle(880,255,100,20));
jButton10.setBounds(new Rectangle(880,305,100,20));
jButton11.setBounds(new Rectangle(880,330,100,20));
jButton12.setBounds(new Rectangle(880,355,100,20));
jButton13.setBounds(new Rectangle(880,380,100,20));
jButton1.setEnabled(false);
jButton2.setEnabled(false);
jButton8.setEnabled(false);
jButton10.setEnabled(false);
jButton11.setEnabled(false);
jButton12.setEnabled(false);
jButton13.setEnabled(false);
this.getContentPane().add(panDe, null);
this.setLocationRelativeTo(null);
//panDe.setBounds(new Rectangle(0,905,110,125));
panneauPlateau.setBounds(new Rectangle(05, 05, 830, 350));
}
public Test(){
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
this.setVisible(true);
this.setTitle("ANDROID");
this.setLocationRelativeTo(null);
//this.setResizable(false);
}
private class PanneauQuestionPhysique extends JPanel{
protected static int hasard = (int)(Math.random()*14);
private String question="";
private String A="";
private String B="";
private String C="";
private String D="";
private String bonnerep="";
private JLabel labelQuestion = new JLabel(question);
private JPanel panneauQP = new JPanel();
private JButton c1 = new JButton(A);
private JButton c2 = new JButton(B);
private JButton c3 = new JButton(C);
private JButton c4 = new JButton(D);
private JLabel labelreponse = new JLabel("Choisissez une reponse.");
private JLabel labelOK = new JLabel("Bravo !");
private JLabel labelF = new JLabel ("<html>Dommage... <br/>La bonne reponse etait "+bonnerep+".<html/>");
public void PanneauQuestionPhysique() {
int hasard = (int)this.chiffreHasard();
String[] questions={"};
String[] A={"les questions sont ici"};
String[] B={"les questions sont ici"};
String[] C={"les questions sont ici"};
String[] D={"les questions sont ici"};
String[] bonnesreps={""};
question = questions[hasard];
* c1 = A[hasard];
* c2 = B[hasard];
* c3 = C[hasard];
* c4 = D[hasard];
* c1.setText(A);
* c2.setText(B);
* c3.setText(C);
* c4.setText(D);
labelF.setText("<html>Dommage... <br/>La bonne reponse etait "+bonnerep+".<html/>");
this.setLayout(new BorderLayout());
this.add(labelQuestion, BorderLayout.NORTH);
this.add(panneauQP, BorderLayout.CENTER);
panneauQP.setLayout(null);
panneauQP.add(c1, null);
panneauQP.add(c2, null);
panneauQP.add(c3, null);
panneauQP.add(c4, null);
panneauQP.add(labelreponse, null);
c1.setBounds(new Rectangle(400, 400, 100, 25));
c2.setBounds(new Rectangle(400, 400, 100, 25));
c3.setBounds(new Rectangle(400, 450, 100, 25));
c4.setBounds(new Rectangle(400, 450, 100, 25));
labelreponse.setBounds(new Rectangle(5, 200, 100, 25));
* c1.addActionListener(new StateListener());
* c2.addActionListener(new StateListener());
* c3.addActionListener(new StateListener());
* c4.addActionListener(new StateListener());
c4.setBackground(PanneauPlateau.skyblue);
labelQuestion.setForeground(Color.BLUE);
}
public int chiffreHasard(){
if (hasard>13){
hasard=0;
}else{
hasard=hasard+1;
}
return hasard;
}
public void paintComponent(Graphics g){
try {
Image img = ImageIO.read(this.getClass().getResourceAsStream("Fcour.jpg"));
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(),this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
public class Test extends JFrame implements ActionListener{ {
private JPanel pan = new JPanel();
private PanneauQuestionPhysique panneauQuestionPhysique1 = new PanneauQuestionPhysique();
protected static int hasard = (int)(Math.random()*14);
protected static Color vert = new Color(34,139,34);
protected static Color lightcyan = new Color(176,196,222);
protected static Color skyblue = new Color(0,191,255);
protected static Color turquoise = new Color(0,206,209);
protected static Color olive = new Color(202,255,112);
protected static boutonRejouer jButton1 = new boutonRejouer();
protected static b0 jButton2 = new b0(lightcyan);
protected static b12 jButton8 = new b12(skyblue);
protected static b16 jButton10 = new b16(Color.CYAN);
protected static b18 jButton11 = new b18(turquoise);
protected static b20 jButton12 = new b20(olive);
protected static b20 jButton13 = new b20(lightcyan);
private PanneauPlateau panneauPlateau = new PanneauPlateau();
protected static PanneauDe panDe = new PanneauDe();
private PanneauTest Panneau = new PanneauTest();
private void jbInit() throws Exception {
this.setSize(new Dimension(1000, 600));
Panneau.setLayout(null);
this.setContentPane(Panneau);
Panneau.add(panneauPlateau, null);
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jButton2, null);
this.getContentPane().add(jButton8, null);
this.getContentPane().add(jButton10, null);
this.getContentPane().add(jButton12, null);
this.getContentPane().add(jButton13, null);
jButton1.setBounds(new Rectangle(880,80,100,20));
jButton2.setBounds(new Rectangle(880,105,100,20));
jButton8.setBounds(new Rectangle(880,255,100,20));
jButton10.setBounds(new Rectangle(880,305,100,20));
jButton11.setBounds(new Rectangle(880,330,100,20));
jButton12.setBounds(new Rectangle(880,355,100,20));
jButton13.setBounds(new Rectangle(880,380,100,20));
jButton1.setEnabled(false);
jButton2.setEnabled(false);
jButton8.setEnabled(false);
jButton10.setEnabled(false);
jButton11.setEnabled(false);
jButton12.setEnabled(false);
jButton13.setEnabled(false);
this.getContentPane().add(panDe, null);
this.setLocationRelativeTo(null);
//panDe.setBounds(new Rectangle(0,905,110,125));
panneauPlateau.setBounds(new Rectangle(05, 05, 830, 350));
}
public Test(){
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
this.setVisible(true);
this.setTitle("ANDROID");
this.setLocationRelativeTo(null);
//this.setResizable(false);
}
private class PanneauQuestionPhysique extends JPanel{
protected static int hasard = (int)(Math.random()*14);
private String question="";
private String A="";
private String B="";
private String C="";
private String D="";
private String bonnerep="";
private JLabel labelQuestion = new JLabel(question);
private JPanel panneauQP = new JPanel();
private JButton c1 = new JButton(A);
private JButton c2 = new JButton(B);
private JButton c3 = new JButton(C);
private JButton c4 = new JButton(D);
private JLabel labelreponse = new JLabel("Choisissez une reponse.");
private JLabel labelOK = new JLabel("Bravo !");
private JLabel labelF = new JLabel ("<html>Dommage... <br/>La bonne reponse etait "+bonnerep+".<html/>");
public void PanneauQuestionPhysique() {
int hasard = (int)this.chiffreHasard();
String[] questions={"};
String[] A={"les questions sont ici"};
String[] B={"les questions sont ici"};
String[] C={"les questions sont ici"};
String[] D={"les questions sont ici"};
String[] bonnesreps={""};
question = questions[hasard];
* c1 = A[hasard];
* c2 = B[hasard];
* c3 = C[hasard];
* c4 = D[hasard];
* c1.setText(A);
* c2.setText(B);
* c3.setText(C);
* c4.setText(D);
labelF.setText("<html>Dommage... <br/>La bonne reponse etait "+bonnerep+".<html/>");
this.setLayout(new BorderLayout());
this.add(labelQuestion, BorderLayout.NORTH);
this.add(panneauQP, BorderLayout.CENTER);
panneauQP.setLayout(null);
panneauQP.add(c1, null);
panneauQP.add(c2, null);
panneauQP.add(c3, null);
panneauQP.add(c4, null);
panneauQP.add(labelreponse, null);
c1.setBounds(new Rectangle(400, 400, 100, 25));
c2.setBounds(new Rectangle(400, 400, 100, 25));
c3.setBounds(new Rectangle(400, 450, 100, 25));
c4.setBounds(new Rectangle(400, 450, 100, 25));
labelreponse.setBounds(new Rectangle(5, 200, 100, 25));
* c1.addActionListener(new StateListener());
* c2.addActionListener(new StateListener());
* c3.addActionListener(new StateListener());
* c4.addActionListener(new StateListener());
c4.setBackground(PanneauPlateau.skyblue);
labelQuestion.setForeground(Color.BLUE);
}
public int chiffreHasard(){
if (hasard>13){
hasard=0;
}else{
hasard=hasard+1;
}
return hasard;
}
public void paintComponent(Graphics g){
try {
Image img = ImageIO.read(this.getClass().getResourceAsStream("Fcour.jpg"));
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(),this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}