Commit 30e05d06 authored by Jérémie's avatar Jérémie
Browse files

Fenetre jeux commenté

parent d343844b
package vue; package vue; //package
import com.sun.source.tree.NewArrayTree; import com.sun.source.tree.NewArrayTree; //importation
import info1.network.Game; import info1.network.Game;
import info1.network.Network; import info1.network.Network;
import info1.ships.BadCoordException; import info1.ships.BadCoordException;
...@@ -16,25 +16,25 @@ import java.awt.event.ActionEvent; ...@@ -16,25 +16,25 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.List; import java.util.List;
public class FenetreJeux extends JFrame { public class FenetreJeux extends JFrame { //création de la classe Fenetre jeux extension de JFrame
private JComboBox pInitialise; private JComboBox pInitialise; //initialisation de tout les widget
private JButton rejoindre; private JButton rejoindre;
private JButton creerPartie; private JButton creerPartie;
private JTextArea zoneMessage; private JTextArea zoneMessage;
public FenetreJeux(String titre){ public FenetreJeux(String titre){ //constructeur
super(titre); super(titre); //envoyer le titre au constructeur de JFrame
JPanel principal = new JPanel(new BorderLayout()); JPanel principal = new JPanel(new BorderLayout()); //nouveau JPanel avec un BorderLayout
this.setContentPane(principal); this.setContentPane(principal); //On l'affiche
JPanel north = new JPanel(new FlowLayout()); JPanel north = new JPanel(new FlowLayout()); //nouveau JPanel avec un flowlayout
principal.add(north,BorderLayout.NORTH); principal.add(north,BorderLayout.NORTH); //qu'on ajoute au Panel principale en haut
JPanel grille = new JPanel(); JPanel grille = new JPanel(); //nouveau panel
grille.setLayout(new GridLayout(11,11)); grille.setLayout(new GridLayout(11,11)); //avec un grid layout
for (int i=0; i<11;i++){ for (int i=0; i<11;i++){ //boucle initialisation axe du tableau
String[] lettres={" ","A","B","C","D","E","F","G","H","I","J"}; String[] lettres={" ","A","B","C","D","E","F","G","H","I","J"};
final JLabel labellettre = new JLabel(lettres[i],SwingConstants.CENTER); final JLabel labellettre = new JLabel(lettres[i],SwingConstants.CENTER);
labellettre.setBorder(BorderFactory.createLineBorder(Color.BLACK)); labellettre.setBorder(BorderFactory.createLineBorder(Color.BLACK));
...@@ -62,34 +62,30 @@ public class FenetreJeux extends JFrame { ...@@ -62,34 +62,30 @@ public class FenetreJeux extends JFrame {
chiffre++; chiffre++;
} }
final Bouttons boutton = new Bouttons(new JButton(), lettre + String.valueOf(chiffre)); final Bouttons boutton = new Bouttons(new JButton(), lettre + String.valueOf(chiffre));
boutton.getButton().setBackground(Color.WHITE); boutton.getButton().setBackground(Color.WHITE); //mettre les bouton en blanc
bouttons[o] = boutton; bouttons[o] = boutton;
o++; o++;
boutton.getButton().setBorder(BorderFactory.createLineBorder(Color.BLACK)); boutton.getButton().setBorder(BorderFactory.createLineBorder(Color.BLACK)); //mettre une bordure sur les boutons
boutton.getButton().addActionListener(new ActionListener() { boutton.getButton().addActionListener(new ActionListener() { //attribuer l'action listener au boutons
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) { //Créer l'actionPerfomed lorsqu'on clique sur un bouton
boutton.getButton().setBackground(Color.RED); boutton.getButton().setBackground(Color.RED); //On met le bouton en rouge
boutton.getButton().setEnabled(false); boutton.getButton().setEnabled(false); //et on le desactive
}}); }});
grille.add(boutton.getButton()); grille.add(boutton.getButton());
} }
lettre++; lettre++;
} }
principal.add(grille,BorderLayout.CENTER); principal.add(grille,BorderLayout.CENTER); //ajout de cette grille au Jpanel principale
JPanel bas = new JPanel(new BorderLayout()); JPanel bas = new JPanel(new BorderLayout()); //Création d'un nouveau Jpanel
JPanel boutons = new JPanel(new FlowLayout()); JPanel boutons = new JPanel(new FlowLayout()); //CRéation d'un nouveau Jpanel
bas.add(boutons,BorderLayout.CENTER); bas.add(boutons,BorderLayout.CENTER); //qui contient la grille de bouton
zoneMessage = new JTextArea("ZONE MESSAGE"); principal.add(bas,BorderLayout.SOUTH); //qu'on ajoute au panel principale
zoneMessage.setPreferredSize(new Dimension(100,100));
bas.add(zoneMessage,BorderLayout.SOUTH);
principal.add(bas,BorderLayout.SOUTH);
JPanel vide = new JPanel(new FlowLayout()); JPanel vide = new JPanel(new FlowLayout());
principal.add(vide,BorderLayout.WEST); principal.add(vide,BorderLayout.WEST);
...@@ -97,5 +93,6 @@ public class FenetreJeux extends JFrame { ...@@ -97,5 +93,6 @@ public class FenetreJeux extends JFrame {
JPanel vide2 = new JPanel(new FlowLayout()); JPanel vide2 = new JPanel(new FlowLayout());
principal.add(vide,BorderLayout.EAST); principal.add(vide,BorderLayout.EAST);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment