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
| package testjdialog;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author GREEXTfl
*/
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
public class Panneau extends JPanel {
private String classe = "Guerrier";
@Override
public void paintComponent(Graphics g) {
//On choisit une couleur de fond pour le rectangle
g.setColor(Color.white);
//On le dessine de sorte qu'il occupe toute la surface
g.fillRect(0, 0, this.getWidth(), this.getHeight());
draw(g);
}
public void setclasse(String inclasse) {
this.classe = inclasse;
}
private void draw(Graphics g) {
try {
if ("Guerrier".equals(this.classe)) {
Image img = ImageIO.read(new File("src/image/g.jpg"));
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
}
if ("Mage".equals(this.classe)) {
Image img = ImageIO.read(new File("src/image/m.png"));
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
}
if ("Clerc".equals(this.classe)) {
Image img = ImageIO.read(new File("src/image/c.gif"));
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
}
if ("Troubadour".equals(this.classe)) {
Image img = ImageIO.read(new File("src/image/t.jpg"));
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
}
} catch (IOException e) {
}
}
} |
Partager