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
| public static void main(String[] args) { jeu jeu=new Jeu(); }
//Constructeur
public Jeu(){
initialiserJeu();
//on inititalise la gestion des clicks
listener = new ClickAction(this);
//on initialise la fenetre et on l'affiche
this.frame=new EchiquierFrame(plateau,listener);
this.frame.setVisible(true);
}
//Fct principale
public void jouer(int i,int j){
[snip de différents trucc]
if(...) {
this.frame.hide();
this.frame.alerte("C'est au joueur noir de jouer!!!!");
this.frame.setVisible(true);
}
// on actualise l'affichage
this.frame.rafraichir(plateau);
}
Dans la classe EchiquierFrame:
public class EchiquierFrame extends JFrame{
//Les deux variables de taille de fenetre
private final static int LARGEUR=400;
private final static int HAUTEUR=425;
//echiquier
EchiquierPanel echiPanel;
public EchiquierFrame(Piece[][] plateau, ClickAction listener) {
super();
// paramètres de la fenetre
setSize(LARGEUR,HAUTEUR);
setResizable(false);
setTitle("Jeu d'échec");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel=new JPanel();
panel.setLayout(new BorderLayout());
//initialisation du plateau compris dans la fenetre
this.echiPanel=new EchiquierPanel(plateau,listener);
echiPanel.repaint();
panel.add(echiPanel,BorderLayout.CENTER);
getContentPane().add(panel);
}
//pour rafraichir le plateau avec le nouveau tableau
public void rafraichir(Piece[][] plateau){
echiPanel.rafraichir(plateau);
echiPanel.repaint();
}
public void alerte(String s){
JOptionPane.showMessageDialog(this, s, "Erreur!", JOptionPane.ERROR_MESSAGE);
} |
Partager