import java.awt.*; import javax.swing.*; public class VueCase extends JPanel { private Case caseN; public VueCase(Case c) { this.caseN = c; this.repaint(); } @Override public void paintComponent(Graphics p) { super.paintComponent(p); Graphics p2 = p.create(); if (this.isOpaque()) { // Obligatoire : on repeint toute la surface avec la couleur de fond p2.setColor(this.getBackground()); p2.fillRect(0, 0, this.getWidth(), this.getHeight()); } if (this.caseN.type.equals("monstre")) { p2.setColor(Color.RED); p2.fillRect(0, 0, this.getWidth(), this.getHeight()); p2.setColor(Color.BLACK); p2.drawString("Monstre, Pv restant :" + caseN.getLabelPv(), (this.getWidth() / 2) - 50, (this.getHeight() / 2) - 10); } if (this.caseN.type.equals("or")) { p2.setColor(Color.YELLOW); p2.fillRect(0, 0, this.getWidth(), this.getHeight()); p2.setColor(Color.BLACK); p2.drawString("Or, Points obtenu :" + caseN.getLabel(), (this.getWidth() / 2) - 50, (this.getHeight() / 2) - 10); } if (this.caseN.type.equals("hero")) { p2.setColor(Color.CYAN); p2.fillRect(0, 0, this.getWidth(), this.getHeight()); p2.setColor(Color.BLACK); p2.drawString("Hero, Pv :" + caseN.getLabelPv(), (this.getWidth() / 2) - 30, (this.getHeight() / 2) - 10); } if (this.caseN.type.equals("potion")) { p2.setColor(Color.GREEN); p2.fillRect(0, 0, this.getWidth(), this.getHeight()); p2.setColor(Color.BLACK); p2.drawString("Potion, Pv rendu: " + caseN.getLabel(), (this.getWidth() / 2) - 60, (this.getHeight() / 2) - 10); } if (this.caseN.type.equals("arme")) { p2.setColor(Color.BLUE); p2.fillRect(0, 0, this.getWidth(), this.getHeight()); p2.setColor(Color.BLACK); p2.drawString("Arme, Atk: " + caseN.getLabel(), (this.getWidth() / 2) - 40, (this.getHeight() / 2) - 10); } } public void setCase(Case c) { this.caseN = c; this.repaint(); } }