package com.jeu4.outil; import com.jeu4.test.Jeu4; class Point { private float score; public Point (float score) { this.score = score; } public float getScore() { return this.score; } ///////////////////////////////////////////// // Modifie l'attribut privée de la classe public void setScore(float nb) { score = nb; } ///////////////////////////////////////////// }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpackage com.jeu4.test; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.JOptionPane; public class Jeu4 extends Frame implements ActionListener { Frame f; CardLayout carte; Panel jeu; Button bouton = new Button("suivant"); Point pointfinal ; public Jeu4() { //panel de la première carte (1ere question) Label situation = new Label("quel est le chanteur du groupe Placebo?"); Panel p1 = new Panel(); p1.add(new JRadioButton("Brian Molko")); p1.add(new JRadioButton("Johnny Halliday")); p1.add(new JRadioButton("Jean pascal")); p1.setBackground(Color.orange); //panel de la deuxieme carte (2eme question) Label situation2 = new Label("qui est 50 cents?"); Panel p2 = new Panel(); p2.add(new JRadioButton("un cycliste")); p2.add(new JRadioButton("Un chanteur")); p2.add(new JRadioButton("Un presentateur TV")); p2.setBackground(Color.green); //panel de la troisième carte (point total) Label situation3 = new Label("point total"); Panel p3 = new Panel(); p3.add(new Label("vos points totaux")); // p3.add(new TextField (getScore)); //p2.add(new JRadioButton("Un chanteur")); // p2.add(new JRadioButton("Un presentateur TV")); p3.setBackground(Color.blue); //panel contenant les deux précédents jeu = new Panel(); carte = new CardLayout(); jeu.setLayout(carte); jeu.add("placebo", p1); jeu.add("50 cents", p2); jeu.add("point total", p3); pointfinal = new Point(0); setLayout(new BorderLayout()); add("South", bouton); add("Center", jeu); p1.add("South", situation); p2.add("South", situation2); bouton.addActionListener(this); setVisible(true); setBounds(150, 150, 300, 250); setTitle("un petit quizz"); int score; } public void actionPerformed(ActionEvent e) { carte.next(jeu); int score = 0; { if (bouton.getLabel().equals("Brian Molko")) pointfinal.setScore(pointfinal.getScore() + 1); //score += 1; // else //score += 0; if (bouton.getLabel().equals("Un chanteur")) pointfinal.setScore(pointfinal.getScore() + 1); //score += 1; //else //score += 0; } } class Point { private float score; public Point (float score) { this.score = score; } public float getScore() { return this.score; } public void setScore(float nb) { score = nb; } } public static void main(String[] args) { Frame f = new Jeu4(); } }
pointfinal.setScore(pointfinal.getScore() +"";