ajout commentaire en en static
This commit is contained in:
parent
28ca45fbc4
commit
f988d9daf9
@ -5,15 +5,19 @@ import java.awt.event.*;
|
||||
import javax.swing.JFrame;
|
||||
import fr.iutfbleau.projetAgile.View.*;
|
||||
|
||||
/**
|
||||
* Observateur des Boutons du Menu
|
||||
*/
|
||||
public class ObservateurMenuSouris implements MouseListener{
|
||||
private Menu m;
|
||||
public ObservateurMenuSouris(Menu m0){
|
||||
this.m=m0;
|
||||
/**
|
||||
* Constructeur
|
||||
*/
|
||||
public ObservateurMenuSouris(){
|
||||
}
|
||||
public void mouseClicked(MouseEvent evenement){
|
||||
BoutonsMenu bout=(BoutonsMenu) (evenement.getComponent());
|
||||
if(bout.getPath()==Menu.PUISSANCE_4){
|
||||
this.m.show(Menu.PUISSANCE_4);
|
||||
Menu.show(Menu.PUISSANCE_4);
|
||||
}
|
||||
} // un bouton cliqué
|
||||
public void mouseEntered(MouseEvent evenement){
|
||||
|
@ -3,10 +3,18 @@ package fr.iutfbleau.projetAgile.View;
|
||||
import javax.swing.JComponent;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Class Dessinant les boutons du menu
|
||||
*/
|
||||
public class BoutonsMenu extends JComponent{
|
||||
private String path;
|
||||
private boolean survol;
|
||||
private Image img;
|
||||
/**
|
||||
* Constructeur
|
||||
* @param path0
|
||||
* il correspond au path de l'image qui devra être afficher
|
||||
*/
|
||||
public BoutonsMenu(String path0){
|
||||
super();
|
||||
this.path=path0;
|
||||
@ -14,13 +22,22 @@ public class BoutonsMenu extends JComponent{
|
||||
this.img = Toolkit.getDefaultToolkit().getImage(cl.getResource("images/"+this.path));
|
||||
this.survol=false;
|
||||
}
|
||||
/**
|
||||
* savoir si le bouton est survoler
|
||||
* @param bol
|
||||
*/
|
||||
public void setSurvol(boolean bol){
|
||||
this.survol=bol;
|
||||
this.repaint();
|
||||
}
|
||||
/**
|
||||
* Connaitre le chemin de l'image et donc le type du jeu
|
||||
* @return le String du jeu du boutons
|
||||
*/
|
||||
public String getPath(){
|
||||
return this.path;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard
|
||||
|
@ -6,17 +6,21 @@ import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import fr.iutfbleau.projetAgile.Controller.*;
|
||||
|
||||
public class Menu extends JPanel{
|
||||
public abstract class Menu{
|
||||
public static String PUISSANCE_4="puissance4.png";
|
||||
private CardLayout cd;
|
||||
private JFrame fenetre;
|
||||
public Menu(CardLayout cd0, JFrame fenetre0){
|
||||
super();
|
||||
this.cd=cd0;
|
||||
this.fenetre=fenetre0;
|
||||
this.setBackground(new Color(31,31,31));
|
||||
private static JFrame frame=new JFrame("Argile");
|
||||
private static CardLayout cd=new CardLayout();
|
||||
|
||||
/**
|
||||
* methode static pour avoir le JPanel Affichant le Menu
|
||||
* @return un JPanel instancier avec les composant du menu
|
||||
*
|
||||
*/
|
||||
public static JPanel InitMenu(){
|
||||
JPanel p=new JPanel();
|
||||
p.setBackground(new Color(31,31,31));
|
||||
GridBagLayout gbl=new GridBagLayout();
|
||||
this.setLayout(gbl);
|
||||
p.setLayout(gbl);
|
||||
GridBagConstraints gbc=new GridBagConstraints();
|
||||
gbc.gridx=0;
|
||||
gbc.gridy=0;
|
||||
@ -33,7 +37,7 @@ public class Menu extends JPanel{
|
||||
titre.setBackground(new Color(55,55,55));
|
||||
titre.setFont(new Font("Serif" ,Font.BOLD, 50));
|
||||
titre.setPreferredSize(new Dimension(400,200));
|
||||
this.add(titre, gbc);
|
||||
p.add(titre, gbc);
|
||||
|
||||
BoutonsMenu puissance_4=new BoutonsMenu(Menu.PUISSANCE_4);
|
||||
BoutonsMenu echecs=new BoutonsMenu("echecs.png");
|
||||
@ -46,7 +50,8 @@ public class Menu extends JPanel{
|
||||
BoutonsMenu CoD=new BoutonsMenu("CoD.png");
|
||||
BoutonsMenu minecraft=new BoutonsMenu("minecraft.png");
|
||||
BoutonsMenu puzzle=new BoutonsMenu("puzzle.png");
|
||||
ObservateurMenuSouris obser=new ObservateurMenuSouris(this);
|
||||
|
||||
ObservateurMenuSouris obser=new ObservateurMenuSouris();
|
||||
puissance_4.addMouseListener(obser);
|
||||
echecs.addMouseListener(obser);
|
||||
dames.addMouseListener(obser);
|
||||
@ -59,19 +64,28 @@ public class Menu extends JPanel{
|
||||
minecraft.addMouseListener(obser);
|
||||
puzzle.addMouseListener(obser);
|
||||
|
||||
this.add(puissance_4, Menu.GridBagConstraintsRetour(0, 1));
|
||||
this.add(echecs, Menu.GridBagConstraintsRetour(1, 1));
|
||||
this.add(dames, Menu.GridBagConstraintsRetour(2, 1));
|
||||
p.add(puissance_4, Menu.GridBagConstraintsRetour(0, 1));
|
||||
p.add(echecs, Menu.GridBagConstraintsRetour(1, 1));
|
||||
p.add(dames, Menu.GridBagConstraintsRetour(2, 1));
|
||||
|
||||
this.add(demineur, Menu.GridBagConstraintsRetour(0, 2));
|
||||
this.add(taquin, Menu.GridBagConstraintsRetour(1, 2));
|
||||
this.add(morpion, Menu.GridBagConstraintsRetour(2, 2));
|
||||
p.add(demineur, Menu.GridBagConstraintsRetour(0, 2));
|
||||
p.add(taquin, Menu.GridBagConstraintsRetour(1, 2));
|
||||
p.add(morpion, Menu.GridBagConstraintsRetour(2, 2));
|
||||
|
||||
this.add(CoD, Menu.GridBagConstraintsRetour(0, 3));
|
||||
this.add(minecraft, Menu.GridBagConstraintsRetour(1, 3));
|
||||
this.add(puzzle, Menu.GridBagConstraintsRetour(2, 3));
|
||||
p.add(CoD, Menu.GridBagConstraintsRetour(0, 3));
|
||||
p.add(minecraft, Menu.GridBagConstraintsRetour(1, 3));
|
||||
p.add(puzzle, Menu.GridBagConstraintsRetour(2, 3));
|
||||
return p;
|
||||
}
|
||||
public static GridBagConstraints GridBagConstraintsRetour(int collonne, int ligne){
|
||||
|
||||
/**
|
||||
* methode priver pour calculer la positions des composants
|
||||
*
|
||||
* @return le GridBagConstraints correspondants aux arguments
|
||||
* @param collonne sa place dans la collonne
|
||||
* @param ligne sa ligne
|
||||
*/
|
||||
private static GridBagConstraints GridBagConstraintsRetour(int collonne, int ligne){
|
||||
GridBagConstraints gbc=new GridBagConstraints();
|
||||
gbc.gridx=collonne;
|
||||
gbc.gridy=ligne;
|
||||
@ -104,14 +118,34 @@ public class Menu extends JPanel{
|
||||
return gbc;
|
||||
}
|
||||
|
||||
public void show(String g) throws IllegalArgumentException
|
||||
{
|
||||
/**
|
||||
* Methode pour changer le cardLayout
|
||||
*
|
||||
* @param g
|
||||
* le string de la carte correspondant
|
||||
* @throws IllegalArgumentException
|
||||
* si l'argument ne correspond pas a une Carte
|
||||
|
||||
*/
|
||||
public static void show(String g) throws IllegalArgumentException
|
||||
{
|
||||
if(g!=Menu.PUISSANCE_4){
|
||||
throw new IllegalArgumentException();
|
||||
}else{
|
||||
if(g==Menu.PUISSANCE_4){
|
||||
this.cd.show(fenetre.getContentPane(), g);
|
||||
Menu.cd.show(Menu.frame.getContentPane(), g);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* getter pouvant initialiser la JFrame
|
||||
* @return
|
||||
* la fenetre
|
||||
*/
|
||||
public static JFrame getFrame(){
|
||||
if(Menu.frame.getLayout()!=Menu.cd){
|
||||
Menu.frame.setLayout(Menu.cd);
|
||||
}
|
||||
return Menu.frame;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user