Bonjour,

Je suis en train de développer avec mon fils un jeu de dé en java.
Nous avons déjà réalisé une version qui tourne sur la console avec des system.out et j'aimerais lui apprendre un peu plus maintenant l'architecture MVC et avec des fenetres SWING.

Mon problème est que j'ai le désagréable sentiment que mon projet est tout simplement un gros bazar alors que je n'en suis qu'au début !!!!

Par exemple, j'ai l'impression que mon contrôleur est commandé par la vue : c'est à dire que j'ai des méthodes dans le contrôleur et comme la vue les appelle, cela donne une impression que ce n'est pas le contrôleur qui contrôle mais on dirait plutôt qu'il se fait donner des ordres par la vue ou le modèle ..... De plus, pour déterminer le nombre de joueurs, l'utilisateur saisit le chiffre puis cliques sur un bouton : c'est le panneau qui passe l'info à la vue, qui passe au contrôleur qui change les données mais le modèle appelle ensuite une fonction qui demande au contrôleur de changer le panneau de la vue -> le controleur se fait encore donner des ordres par l'intermédiaire d'une fontion du controleur appelée depuis le modèle ou la vue.

Aussi, le contrôleur demande à la vue d'afficher mais mes méthodes ne renvoient rien (void) car c'est une action sur un bouton qui fait changer d'état ou de phase. Ne faudrait-il pas que lorsque un ordre est lancé par le contrôleur, la vue ou le modèle réponde true ou false ou une autre donnée disant que l'action a été faite ?

Je vous envoie le projet en entier et je cous remercie par avance pour vos aides !

déjà voici la structure des packages :
Nom : Capture d’écran du 2022-10-23 22-56-57.png
Affichages : 86
Taille : 13,5 Ko

Classe JeuDeDes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
package com;

import com.controller.Controller;

public class JeuDeDes {

	public static void main(String[] args) {
		Controller control = new Controller();
	}
}
Classe Controller :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package com.controller;

import java.util.ArrayList;

import com.model.Joueur;
import com.model.Model;
import com.model.Phases;
import com.view.Fenetre;

public class Controller {
	public Fenetre fenetre = null;
	Model model = null;
	Phases phase = Phases.nbreJoueurs;
	Joueur joueur = null;
	ArrayList<Joueur> joueurs = new ArrayList<Joueur>();
	
	public Controller() {
		fenetre = new Fenetre(this);
		model = new Model(this);
		
		fenetre.phaseNbreJoueurs();
	}
	
	public void setNbreJoueurs(int _nbreJoueurs) {
		model.setNbreJoueurs(_nbreJoueurs);
	}
	
	public void setJoueurs(String[] prenoms) {
		for(String prenom : prenoms) {
			joueur = new Joueur(5000, prenom);
			joueurs.add(joueur);
		}
	}
	
	public void nextPhase(int _nbreJoueurs) {
		
		if(phase == Phases.nbreJoueurs) {
			fenetre.phasePrenoms(_nbreJoueurs);
		}
	}
}
Classe Fenetre :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package com.view;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.controller.Controller;
import com.view.panels.PanneauCommandes;
import com.view.panels.PanneauDes;
import com.view.panels.PanneauJoueurs;
import com.view.panels.PanneauNbreJoueurs;
import com.view.panels.PanneauPrenoms;
import com.view.panels.PanneauScore;

public class Fenetre extends JFrame{
	public Controller ctrl = null;
	JPanel panneau = null;
	PanneauNbreJoueurs pnj = null;
	PanneauPrenoms pp = null;
	
	public Fenetre(Controller _ctrl) {
		super("Jeu de dés");
		
		WindowListener l = new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		};
		addWindowListener(l);
		
		this.ctrl = _ctrl;
		
		this.setExtendedState(JFrame.MAXIMIZED_BOTH);
		this.setVisible(true);

		panneau = new JPanel(new BorderLayout());
	}
	
	public void phaseNbreJoueurs() {
		pnj = new PanneauNbreJoueurs(ctrl);
		
		panneau.add(pnj, BorderLayout.CENTER);
		
		this.setContentPane(panneau);
		this.setVisible(true);
	}
	
	public void phasePrenoms(int _nbreJoueurs) {
		panneau.remove(pnj);
		pp = new PanneauPrenoms(ctrl, _nbreJoueurs);
		
		this.add(pp);
		this.setVisible(true);
	}
	
	public void phaseJeu() {
		panneau.remove(pp);
		
		PanneauJoueurs pj = new PanneauJoueurs();
		PanneauCommandes pc = new PanneauCommandes();
		PanneauScore ps = new PanneauScore();
		PanneauDes pd = new PanneauDes();
		
		panneau.add(ps, BorderLayout.EAST);
		panneau.add(pj, BorderLayout.NORTH);
		panneau.add(pd, BorderLayout.CENTER);
		panneau.add(pc, BorderLayout.SOUTH);
		
		this.setContentPane(panneau);
		this.setVisible(true);
	}
}
Classe Model :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package com.model;

import com.controller.Controller;

public class Model {
	private Regles regles = null;
	private Controller ctrl = null;
	
	public Model(Controller _ctrl) {
		this.ctrl = _ctrl;
		regles = new Regles(this);
	}
	
	public void setNbreJoueurs(int _nbreJoueurs) {
		regles.setNbreJoueurs(_nbreJoueurs);
	}
	
	public int getNbreJoueurs() {
		return regles.getNbreJoueurs();
	}
	
	public void nbreJoueursChanged() {
		ctrl.nextPhase(regles.getNbreJoueurs());
	}
	//TODO méthodes creerJoueurs qui renvoie un tableau
	//TODO méthodes lance dés qui renvoie le tableau des valeurs des dés
}
Classe PanneauJoueurs :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package com.view.panels;

import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;

import com.view.drawings.LabelsRoundedBorder;

public class PanneauJoueurs extends JPanel {
	public PanneauJoueurs() {
		super();
		
		this.setLayout(new FlowLayout());
		
		JLabel labelJoueur1 = new JLabel("Louis");
		JLabel labelJoueur2 = new JLabel("Lilie");
		JLabel labelJoueur3 = new JLabel("Papa");
		
		labelJoueur1.setBackground(Color.YELLOW);
		labelJoueur1.setForeground(Color.BLUE);
		labelJoueur1.setOpaque(true);
		labelJoueur1.setBorder(new LabelsRoundedBorder(Color.BLACK, 20));
		
		labelJoueur2.setBackground(Color.LIGHT_GRAY);
		labelJoueur2.setForeground(Color.BLACK);
		labelJoueur2.setOpaque(true);
		labelJoueur2.setBorder(new LabelsRoundedBorder(Color.BLACK, 20));
		
		labelJoueur3.setBackground(Color.LIGHT_GRAY);
		labelJoueur3.setForeground(Color.BLACK);
		labelJoueur3.setOpaque(true);
		labelJoueur3.setBorder(new LabelsRoundedBorder(Color.BLACK, 20));
		
		this.add(labelJoueur1);
		this.add(labelJoueur2);
		this.add(labelJoueur3);
	}
}
Classe PanneauCommandes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package com.view.panels;

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class PanneauCommandes extends JPanel {
	public PanneauCommandes() {
		super(new FlowLayout());
		
		JButton button = new JButton("Lancer les dés");
		
		this.add(button);
	}
}
Classe PanneauScore :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.view.panels;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class PanneauScore extends JPanel {
	public PanneauScore() {
		super();

		int score1 = 5000;
		int score2 = 3550;
		
		JLabel joueur1 = new JLabel("Louis = " + score1);
		JLabel joueur2 = new JLabel("Lilie = " + score2);
		this.add(joueur1);
		this.add(joueur2);
		
		this.setLayout (new BoxLayout (this, BoxLayout.Y_AXIS)); 
	}
}
Classe PanneauDes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package com.view.panels;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JPanel;

import com.view.drawings.DessinDes;

public class PanneauDes extends JPanel {
	
	public PanneauDes() {
		super();
		
		DessinDes dd1 = new DessinDes(1, Color.PINK, 100, 200);
		DessinDes dd2 = new DessinDes(2, Color.MAGENTA, 200, 500);
		DessinDes dd3 = new DessinDes(3, Color.WHITE, 100, 400);
		DessinDes dd4 = new DessinDes(4, Color.BLACK, 300, 300);
		DessinDes dd5 = new DessinDes(5, Color.BLUE, 500 , 100);
		
		//dé1
		this.add(dd1);
		
		//dé2
		this.add(dd2);
		
		//dé3
		this.add(dd3);
		
		//dé4
		this.add(dd4);
		
		//dé5
		this.add(dd5);
	}
}
Classe PanneauNbreJoueurs :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package com.view.panels;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

import com.controller.Controller;

public class PanneauNbreJoueurs extends JPanel {
	
	private int nbreJoueurs = 0;
	private Controller ctrl = null;
	
	public PanneauNbreJoueurs(Controller _ctrl) {
		super();		
		
		ctrl = _ctrl;
		
		JLabel lblNbreJoueurs = new JLabel("Combien de joueurs ? ");

		lblNbreJoueurs.setFont(new Font("Monospaced", Font.PLAIN, 40));
		this.add(lblNbreJoueurs);
		
		JTextField tf = new JTextField();
		tf.setColumns(5);
		tf.setPreferredSize(new Dimension( 300, 48 ));
		tf.setBackground(this.getBackground());
		tf.setFont(new Font("Monospaced", Font.PLAIN, 40));
		this.add(tf);
		
		JLabel lblVide = new JLabel("           ");
		this.add(lblVide);
		
		JButton btnValider = new JButton("Valider");
		btnValider.setPreferredSize(new Dimension(300, 48));
		this.add(btnValider);
		

		JLabel erreur = new JLabel("Ne saisir que des chiffres entre 2 et 9 !");
		erreur.setFont(new Font("Monospaced", Font.BOLD, 48));
		erreur.setForeground(Color.RED);
		erreur.setVisible(false);
		this.add(erreur);
		
		btnValider.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				try {
					int nbre = Integer.parseInt(tf.getText());
					if(nbre < 10 && nbre > 1) {
						ctrl.setNbreJoueurs(nbre);
					} else {
						erreur.setVisible(true);
					}
				} catch(NumberFormatException nfe) {
					erreur.setVisible(true);
				}
			}
		});		
		
		this.setLocation(200, 500);
		
	}
}
Classe PanneauPrenoms :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package com.view.panels;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

import com.controller.Controller;
import com.view.panels.layouts.SpringUtilities;

public class PanneauPrenoms extends JPanel {
	Controller ctrl = null;
	int nbreJoueurs = 0;
	JPanel panelPrenoms = null;
	ArrayList<JTextField> listTF = new ArrayList<JTextField>();
	
	public PanneauPrenoms(Controller _ctrl, int _nbreJoueurs) {
		super(new BorderLayout());
		
		this.ctrl = _ctrl;
		this.nbreJoueurs = _nbreJoueurs;

		panelPrenoms = new JPanel(new SpringLayout());
		
		for(int i = 1; i <= nbreJoueurs; i++) {
			
			JLabel lblPrenoms = new JLabel("Prénom du joueur " + i + " ?", JLabel.TRAILING);
			lblPrenoms.setFont(new Font("Monospaced", Font.PLAIN, 30));
			
			panelPrenoms.add(lblPrenoms);
			
			JTextField tf = new JTextField();
			lblPrenoms.setLabelFor(tf);
			tf.setColumns(5);
			tf.setPreferredSize(new Dimension( 600, 30 ));
			tf.setBackground(this.getBackground());
			tf.setFont(new Font("Monospaced", Font.PLAIN, 40));
			
			listTF.add(tf);
			
			panelPrenoms.add(tf);
		}
		
		SpringUtilities.makeCompactGrid(panelPrenoms,
                nbreJoueurs, 2, //rows, cols
                6, 6,        //initX, initY
                6, 6);       //xPad, yPad
		
		
		this.add(panelPrenoms, BorderLayout.CENTER);
		
		JPanel panelBouton = new JPanel();
		
		JButton btnValider = new JButton("Valider");
		btnValider.setPreferredSize(new Dimension(300, 48));
		panelBouton.add(btnValider);
		
		this.add(panelBouton, BorderLayout.SOUTH);
		
		btnValider.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String[] prenoms = new String[nbreJoueurs];
				int i = 0;
				for(JTextField eachTF : listTF) {
					prenoms[i] = eachTF.getText();
					i++;
				}
				
				ctrl.setJoueurs(prenoms);
			}
		});	
	}
}
Classe DessinDes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package com.view.drawings;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JComponent;

public class DessinDes extends JComponent {
	
	private Color pointsCoul = null;
	private int nb = 1;
	private int pos_y = 0;
	private int pos_x = 0;
	
	public DessinDes(int _nb, Color _pointsCoul, int _pos_x, int _pos_y) {
		super();
		this.setPreferredSize(new Dimension(100, 100));
		this.pointsCoul = _pointsCoul;
		this.nb = _nb;
		this.pos_y = _pos_y;
		this.pos_x = _pos_x;
	}
	
	@Override
    public void paintComponent(Graphics g) {
		// passage du contexte graphique
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D)g;
		
        g.setColor(Color.RED);
        g.fillRect(0, 0, 80, 80);
        g.setColor(Color.GREEN);
        g.drawRect(0, 0, 80, 80);
        
        // choix de la couleur pour les points
        g.setColor(pointsCoul);
        
        switch(nb) {
	        case 1:
	        	//Dé 1
	            g.fillOval(33, 33, 15, 15);	
	            break;
	        case 2:
	            //Dé 2
	            g.fillOval(55, 10, 15, 15);
	            g.fillOval(10, 55, 15, 15);
	            break;
	        case 3:
	            //Dé 3
	            g.fillOval(55, 10, 15, 15);
	            g.fillOval(33, 33, 15, 15);
	            g.fillOval(10, 55, 15, 15);
	            break;
	        case 4:
	            //Dé 4
	            g.fillOval(10, 10, 15, 15);
	            g.fillOval(55, 10, 15, 15);
	            g.fillOval(10, 55, 15, 15);
	            g.fillOval(55, 55, 15, 15);
	            break;
	        case 5:
	            g.fillOval(10, 10, 15, 15);
	            g.fillOval(55, 10, 15, 15);
	            g.fillOval(33, 33, 15, 15);	
	            g.fillOval(10, 55, 15, 15);
	            g.fillOval(55, 55, 15, 15);
	        	break;
	        case 6:
	            //Dé 6
	            g.fillOval(10, 10, 15, 15);
	            g.fillOval(55, 10, 15, 15);
	            g.fillOval(10, 33, 15, 15);
	            g.fillOval(55, 33, 15, 15);
	            g.fillOval(10, 55, 15, 15);
	            g.fillOval(55, 55, 15, 15);
	        	break;
        }

		this.setLocation(pos_x, pos_y);
    }
   
}
Classe LabelsRoundedBorder :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package com.view.drawings;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.RenderingHints;
import java.awt.geom.RoundRectangle2D;

import javax.swing.border.AbstractBorder;

public class LabelsRoundedBorder extends AbstractBorder {

    private final Color color;
    private final int gap;

    public LabelsRoundedBorder(Color c, int g) {
        color = c;
        gap = g;
    }

    @Override
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    	Graphics2D g2d = (Graphics2D) g.create();
        g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
        g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        g2d.setColor(color);
        g2d.draw(new RoundRectangle2D.Double(x + 1, y + 1, width - 2, height - 2, gap, gap));
        g2d.dispose();
    }

    @Override
    public Insets getBorderInsets(Component c) {
        return (getBorderInsets(c, new Insets(gap, gap, gap, gap)));
    }

    @Override
    public Insets getBorderInsets(Component c, Insets insets) {
        insets.left = insets.top = insets.right = insets.bottom = gap / 2;
        return insets;
    }

    @Override
    public boolean isBorderOpaque() {
        return false;
    }
}
Classe SpingUtilities :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package com.view.panels.layouts;


import javax.swing.*;
import javax.swing.SpringLayout;
import java.awt.*;

/**
 * A 1.4 file that provides utility methods for
 * creating form- or grid-style layouts with SpringLayout.
 * These utilities are used by several programs, such as
 * SpringBox and SpringCompactGrid.
 */
public class SpringUtilities {
    /**
     * A debugging utility that prints to stdout the component's
     * minimum, preferred, and maximum sizes.
     */
    public static void printSizes(Component c) {
        System.out.println("minimumSize = " + c.getMinimumSize());
        System.out.println("preferredSize = " + c.getPreferredSize());
        System.out.println("maximumSize = " + c.getMaximumSize());
    }

    /**
     * Aligns the first <code>rows</code> * <code>cols</code>
     * components of <code>parent</code> in
     * a grid. Each component is as big as the maximum
     * preferred width and height of the components.
     * The parent is made just big enough to fit them all.
     *
     * @param rows number of rows
     * @param cols number of columns
     * @param initialX x location to start the grid at
     * @param initialY y location to start the grid at
     * @param xPad x padding between cells
     * @param yPad y padding between cells
     */
    public static void makeGrid(Container parent,
                                int rows, int cols,
                                int initialX, int initialY,
                                int xPad, int yPad) {
        SpringLayout layout;
        try {
            layout = (SpringLayout)parent.getLayout();
        } catch (ClassCastException exc) {
            System.err.println("The first argument to makeGrid must use SpringLayout.");
            return;
        }

        Spring xPadSpring = Spring.constant(xPad);
        Spring yPadSpring = Spring.constant(yPad);
        Spring initialXSpring = Spring.constant(initialX);
        Spring initialYSpring = Spring.constant(initialY);
        int max = rows * cols;

        //Calculate Springs that are the max of the width/height so that all
        //cells have the same size.
        Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0)).
                                    getWidth();
        Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0)).
                                    getHeight();
        for (int i = 1; i < max; i++) {
            SpringLayout.Constraints cons = layout.getConstraints(
                                            parent.getComponent(i));

            maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
            maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
        }

        //Apply the new width/height Spring. This forces all the
        //components to have the same size.
        for (int i = 0; i < max; i++) {
            SpringLayout.Constraints cons = layout.getConstraints(
                                            parent.getComponent(i));

            cons.setWidth(maxWidthSpring);
            cons.setHeight(maxHeightSpring);
        }

        //Then adjust the x/y constraints of all the cells so that they
        //are aligned in a grid.
        SpringLayout.Constraints lastCons = null;
        SpringLayout.Constraints lastRowCons = null;
        for (int i = 0; i < max; i++) {
            SpringLayout.Constraints cons = layout.getConstraints(
                                                 parent.getComponent(i));
            if (i % cols == 0) { //start of new row
                lastRowCons = lastCons;
                cons.setX(initialXSpring);
            } else { //x position depends on previous component
                cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST),
                                     xPadSpring));
            }

            if (i / cols == 0) { //first row
                cons.setY(initialYSpring);
            } else { //y position depends on previous row
                cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH),
                                     yPadSpring));
            }
            lastCons = cons;
        }

        //Set the parent's size.
        SpringLayout.Constraints pCons = layout.getConstraints(parent);
        pCons.setConstraint(SpringLayout.SOUTH,
                            Spring.sum(
                                Spring.constant(yPad),
                                lastCons.getConstraint(SpringLayout.SOUTH)));
        pCons.setConstraint(SpringLayout.EAST,
                            Spring.sum(
                                Spring.constant(xPad),
                                lastCons.getConstraint(SpringLayout.EAST)));
    }

    /* Used by makeCompactGrid. */
    private static SpringLayout.Constraints getConstraintsForCell(
                                                int row, int col,
                                                Container parent,
                                                int cols) {
        SpringLayout layout = (SpringLayout) parent.getLayout();
        Component c = parent.getComponent(row * cols + col);
        return layout.getConstraints(c);
    }

    /**
     * Aligns the first <code>rows</code> * <code>cols</code>
     * components of <code>parent</code> in
     * a grid. Each component in a column is as wide as the maximum
     * preferred width of the components in that column;
     * height is similarly determined for each row.
     * The parent is made just big enough to fit them all.
     *
     * @param rows number of rows
     * @param cols number of columns
     * @param initialX x location to start the grid at
     * @param initialY y location to start the grid at
     * @param xPad x padding between cells
     * @param yPad y padding between cells
     */
    public static void makeCompactGrid(Container parent,
                                       int rows, int cols,
                                       int initialX, int initialY,
                                       int xPad, int yPad) {
        SpringLayout layout;
        try {
            layout = (SpringLayout)parent.getLayout();
        } catch (ClassCastException exc) {
            System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
            return;
        }

        //Align all cells in each column and make them the same width.
        Spring x = Spring.constant(initialX);
        for (int c = 0; c < cols; c++) {
            Spring width = Spring.constant(0);
            for (int r = 0; r < rows; r++) {
                width = Spring.max(width,
                                   getConstraintsForCell(r, c, parent, cols).
                                       getWidth());
            }
            for (int r = 0; r < rows; r++) {
                SpringLayout.Constraints constraints =
                        getConstraintsForCell(r, c, parent, cols);
                constraints.setX(x);
                constraints.setWidth(width);
            }
            x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
        }

        //Align all cells in each row and make them the same height.
        Spring y = Spring.constant(initialY);
        for (int r = 0; r < rows; r++) {
            Spring height = Spring.constant(0);
            for (int c = 0; c < cols; c++) {
                height = Spring.max(height,
                                    getConstraintsForCell(r, c, parent, cols).
                                        getHeight());
            }
            for (int c = 0; c < cols; c++) {
                SpringLayout.Constraints constraints =
                        getConstraintsForCell(r, c, parent, cols);
                constraints.setY(y);
                constraints.setHeight(height);
            }
            y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
        }

        //Set the parent's size.
        SpringLayout.Constraints pCons = layout.getConstraints(parent);
        pCons.setConstraint(SpringLayout.SOUTH, y);
        pCons.setConstraint(SpringLayout.EAST, x);
    }
}
Classe Joueur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package com.model;

public class Joueur {
	//******attributs
	int nbrePts;	//nombre de points de départ pour chaque joueur
	int tour;	//ordre de départ
	String prenom;
	
	//******constructeurs
	public Joueur(int _nbrePts, String _prenom){
		this.nbrePts = _nbrePts;
		//this.tour = _tour;
		this.prenom = _prenom;
	}
	
	//******Setters Getters
	public void setNbrePts(int _nbrePts){
			this.nbrePts = _nbrePts;
	}
	
	public int getNbrePts(){
		return nbrePts;
	}
	
	public void setTour(int _tour){
		this.tour = _tour;
	}
	
	public int getTour(){
		return tour;
	}
	
	public void setPrenom(String _prenom){
		this.prenom = _prenom;
	}
	
	public String getPrenom(){
		return prenom;
	} 
}
Classe Regles :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.model;


public class Regles {
	private int PointsDepart;
	private int nbreJoueurs = 0;
    private Model model = null;
    
	public Regles(Model _model) {
		this.model = _model;
	}
	
	public int getNbreJoueurs() {
		return nbreJoueurs;
	}
	
	public void setNbreJoueurs(int _nbreJoueurs){
		this.nbreJoueurs = _nbreJoueurs;
		
		model.nbreJoueursChanged();
	}	
}
Enum Phases :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
package com.model;

public enum Phases {
	nbreJoueurs,
	prenomsJoueurs,
	jeu,
	fin
}