ajout changement menu

This commit is contained in:
martins 2022-10-23 22:50:21 +02:00
parent ff052e94ac
commit ac73e0412f
4 changed files with 39 additions and 13 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

View File

@ -2,6 +2,7 @@ package fr.iutfbleau.projetAgile.Menu.View;
import javax.swing.JComponent;
import java.awt.*;
import java.awt.geom.*;
/**
* Class Dessinant les boutons du menu
@ -10,17 +11,19 @@ public class BoutonsMenu extends JComponent{
private String path;
private boolean survol;
private Image img;
private boolean disponibiliter;
/**
* Constructeur
* @param path0
* il correspond au path de l'image qui devra être afficher
*/
public BoutonsMenu(String path0){
public BoutonsMenu(String path0, boolean disponibiliter0){
super();
this.path=path0;
ClassLoader cl = Thread.currentThread().getContextClassLoader();
this.img = Toolkit.getDefaultToolkit().getImage(cl.getResource("images/"+this.path));
this.img = Toolkit.getDefaultToolkit().getImage(cl.getResource("images/"+this.path+".png"));
this.survol=false;
this.disponibiliter=disponibiliter0;
}
/**
* savoir si le bouton est survoler
@ -49,10 +52,33 @@ public class BoutonsMenu extends JComponent{
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
// maintenant on dessine ce que l'on veut
String dispo;
if(this.disponibiliter==true){
secondPinceau.setColor(new Color(255,0,0,200));
dispo="Disponible";
}else{
secondPinceau.setColor(new Color(100,100,100,200));
dispo="Indisponible";
}
if(this.survol==false){
secondPinceau.drawImage(this.img, 5, 5, this.getWidth()-10, this.getHeight()-10, this);
secondPinceau.fillRoundRect(5, 5, this.getWidth()-10, this.getHeight()-10, this.getWidth()/100*9, this.getHeight()/100*29);
}else{
secondPinceau.drawImage(this.img, 0, 0, this.getWidth(), this.getHeight(), this);
secondPinceau.drawImage(this.img, 0, 0, this.getWidth()-5, this.getHeight()-5, this);
secondPinceau.fillRoundRect(0, 0, this.getWidth()-5, this.getHeight()-5, this.getWidth()/100*9, this.getHeight()/100*29);
}
secondPinceau.setColor(new Color(255, 255, 255));
secondPinceau.setFont(new Font(Font.SANS_SERIF, Font.BOLD, (this.getWidth()/10)));
FontMetrics metrics = secondPinceau.getFontMetrics(new Font(Font.SANS_SERIF, Font.BOLD, this.getWidth()/10));
Rectangle rect= new Rectangle(0, 0, this.getWidth(), this.getHeight());
int x = rect.x + (rect.width - metrics.stringWidth(this.path)) / 2;
int y = rect.y + ((rect.height - metrics.getHeight()) / 3) + metrics.getAscent();
secondPinceau.drawString((this.path.toUpperCase()), x, y);
//DISPO OU PAS
secondPinceau.setFont(new Font(Font.SANS_SERIF, Font.BOLD, (this.getWidth()/20)));
metrics = secondPinceau.getFontMetrics(new Font(Font.SANS_SERIF, Font.BOLD, this.getWidth()/20));
x = rect.x + (rect.width - metrics.stringWidth(dispo)) / 2;
y = rect.y + ((rect.height - metrics.getHeight()) / 3*2) + metrics.getAscent();
secondPinceau.drawString(dispo, x, y);
}
}

View File

@ -7,7 +7,7 @@ import javax.swing.JLabel;
import fr.iutfbleau.projetAgile.Menu.Controller.*;
public abstract class Menu{
public static String PUISSANCE_4="puissance4.png";
public static String PUISSANCE_4="puissance4";
private static JFrame frame=new JFrame("Argile");
private static CardLayout cd=new CardLayout();
@ -39,17 +39,17 @@ public abstract class Menu{
titre.setPreferredSize(new Dimension(400,200));
p.add(titre, gbc);
BoutonsMenu puissance_4=new BoutonsMenu(Menu.PUISSANCE_4);
BoutonsMenu echecs=new BoutonsMenu("echecs.png");
BoutonsMenu dames=new BoutonsMenu("dames.png");
BoutonsMenu puissance_4=new BoutonsMenu(Menu.PUISSANCE_4, true);
BoutonsMenu echecs=new BoutonsMenu("echecs", false);
BoutonsMenu dames=new BoutonsMenu("dames", false);
BoutonsMenu demineur=new BoutonsMenu("demineur.png");
BoutonsMenu taquin=new BoutonsMenu("taquin.png");
BoutonsMenu morpion=new BoutonsMenu("morpion.png");
BoutonsMenu demineur=new BoutonsMenu("demineur", false);
BoutonsMenu taquin=new BoutonsMenu("taquin", false);
BoutonsMenu morpion=new BoutonsMenu("morpion", false);
BoutonsMenu CoD=new BoutonsMenu("CoD.png");
BoutonsMenu minecraft=new BoutonsMenu("minecraft.png");
BoutonsMenu puzzle=new BoutonsMenu("puzzle.png");
BoutonsMenu CoD=new BoutonsMenu("snake", false);
BoutonsMenu minecraft=new BoutonsMenu("minigolf", false);
BoutonsMenu puzzle=new BoutonsMenu("puzzle", false);
ObservateurMenuSouris obser=new ObservateurMenuSouris();
puissance_4.addMouseListener(obser);