138 lines
5.7 KiB
Java
138 lines
5.7 KiB
Java
import java.awt.*;
|
|
import javax.swing.*;
|
|
import javax.swing.JComponent;
|
|
|
|
public class paintMenuJeu extends JComponent{
|
|
private int choix;
|
|
private int score;
|
|
private Image un, deux, trois, quatre, cinq, six, sept, huit, neuf, zero, err, sav, lose, win, replay;
|
|
private boolean survol;
|
|
public paintMenuJeu(int choix0, int score0){
|
|
this.choix=choix0;
|
|
this.score=score0;
|
|
this.un=Toolkit.getDefaultToolkit().getImage("./IMAGE/unD.png");
|
|
this.deux=Toolkit.getDefaultToolkit().getImage("./IMAGE/deuxD.png");
|
|
this.trois=Toolkit.getDefaultToolkit().getImage("./IMAGE/troisD.png");
|
|
this.quatre=Toolkit.getDefaultToolkit().getImage("./IMAGE/quatreD.png");
|
|
this.cinq=Toolkit.getDefaultToolkit().getImage("./IMAGE/cinqD.png");
|
|
this.six=Toolkit.getDefaultToolkit().getImage("./IMAGE/sixD.png");
|
|
this.sept=Toolkit.getDefaultToolkit().getImage("./IMAGE/septD.png");
|
|
this.huit=Toolkit.getDefaultToolkit().getImage("./IMAGE/huitD.png");
|
|
this.neuf=Toolkit.getDefaultToolkit().getImage("./IMAGE/neufD.png");
|
|
this.zero=Toolkit.getDefaultToolkit().getImage("./IMAGE/zeroD.png");
|
|
this.err=Toolkit.getDefaultToolkit().getImage("./IMAGE/err.png");
|
|
this.sav=Toolkit.getDefaultToolkit().getImage("./IMAGE/sav.png");
|
|
this.lose=Toolkit.getDefaultToolkit().getImage("./IMAGE/lose.png");
|
|
this.win=Toolkit.getDefaultToolkit().getImage("./IMAGE/win.png");
|
|
this.replay=Toolkit.getDefaultToolkit().getImage("./IMAGE/replay.png");
|
|
this.survol=false;
|
|
}
|
|
public void setChoix(int choix0){
|
|
this.choix=choix0;
|
|
this.repaint();
|
|
}
|
|
public void setScore(int score0){
|
|
this.score=score0;
|
|
this.repaint();
|
|
}
|
|
public int getScore(){
|
|
return this.score;
|
|
}
|
|
public void setSurvol(boolean survol0){
|
|
this.survol=survol0;
|
|
this.repaint();
|
|
}
|
|
@Override
|
|
protected void paintComponent(Graphics pinceau) {
|
|
// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard
|
|
Graphics secondPinceau = pinceau.create();
|
|
// obligatoire : si le composant n'est pas censé être transparent
|
|
if (this.isOpaque()) {
|
|
// obligatoire : on repeint toute la surface avec la couleur de fond
|
|
secondPinceau.setColor(this.getBackground());
|
|
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
|
}
|
|
//On paint ce que l'on veut maintenant
|
|
secondPinceau.setColor(new Color(0,0,0));
|
|
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
|
if(this.choix==1){
|
|
int nombre=this.score/100;
|
|
this.paintNombre(secondPinceau, nombre);
|
|
}
|
|
if(this.choix==2){
|
|
int nombre=this.score;
|
|
if(nombre>=100){
|
|
nombre=this.score-100*(this.score/100);
|
|
}
|
|
nombre=nombre/10;
|
|
this.paintNombre(secondPinceau, nombre);
|
|
}
|
|
if(this.choix==3){
|
|
int nombre=this.score;
|
|
if(nombre>=100){
|
|
nombre=this.score-100*(this.score/100);
|
|
}
|
|
if(nombre>=10){
|
|
nombre=this.score-10*(this.score/10);
|
|
}
|
|
this.paintNombre(secondPinceau, nombre);
|
|
}
|
|
if(this.choix==4){
|
|
if(this.survol==true){
|
|
secondPinceau.setColor(new Color(0,255,0));
|
|
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
|
}
|
|
secondPinceau.drawImage(this.sav, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
if(this.choix==5){
|
|
secondPinceau.drawImage(this.lose, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
if(this.choix==6){
|
|
secondPinceau.drawImage(this.win, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
if(this.choix==7){
|
|
if(this.survol==true){
|
|
secondPinceau.setColor(new Color(0,255,0));
|
|
secondPinceau.fillRect(0, 0, this.getWidth()/16*5, this.getHeight()/16*5);
|
|
}
|
|
secondPinceau.drawImage(this.replay, 0, 0, this.getWidth()/16*4, this.getHeight()/16*4 ,this);
|
|
}
|
|
}
|
|
private void paintNombre(Graphics secondPinceau, int nombre){
|
|
if(this.score>=0){
|
|
if(nombre==1){
|
|
secondPinceau.drawImage(this.un, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
if(nombre==2){
|
|
secondPinceau.drawImage(this.deux, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
if(nombre==3){
|
|
secondPinceau.drawImage(this.trois, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
if(nombre==4){
|
|
secondPinceau.drawImage(this.quatre, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
if(nombre==5){
|
|
secondPinceau.drawImage(this.cinq, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
if(nombre==6){
|
|
secondPinceau.drawImage(this.six, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
if(nombre==7){
|
|
secondPinceau.drawImage(this.sept, this.getWidth()/6, this.getHeight()/20*5, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
if(nombre==8){
|
|
secondPinceau.drawImage(this.huit, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
if(nombre==9){
|
|
secondPinceau.drawImage(this.neuf, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
if(nombre==0){
|
|
secondPinceau.drawImage(this.zero, this.getWidth()/6, this.getHeight()/6, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
}else{
|
|
secondPinceau.drawImage(this.err, this.getWidth()/20*5, this.getHeight()/20*5, this.getWidth()/6*4, this.getHeight()/6*4 ,this);
|
|
}
|
|
|
|
}
|
|
} |