import javax.swing.*; import java.awt.*; public class HangmanPanel extends JPanel { private int errors = 0; public HangmanPanel() { setPreferredSize(new Dimension(300, 400)); setBackground(Color.WHITE); } /*mettre à jour les erreurs*/ public void setErrors(int errors) { this.errors = errors; repaint(); } /*Dessiner le pendu*/ protected void paintComponent(Graphics g) { super.paintComponent(g); // Amélioration visuelle g.setColor(Color.BLACK); g.setFont(new Font("Arial", Font.BOLD, 16)); g.drawString("Erreurs: " + errors + "/9", 50, 30); // Dessin du pendu g.drawLine(50, 300, 200, 300); // Base g.drawLine(125, 300, 125, 50); // Poteau vertical g.drawLine(125, 50, 250, 50); // Poteau horizontal g.drawLine(250, 50, 250, 80); // Corde // Parties du bonhomme if (errors > 0) g.drawOval(230, 80, 40, 40); // Tête if (errors > 1) g.drawLine(250, 120, 250, 200); // Corps if (errors > 2) g.drawLine(250, 140, 220, 170); // Bras gauche if (errors > 3) g.drawLine(250, 140, 280, 170); // Bras droit if (errors > 4) g.drawLine(250, 200, 220, 250); // Jambe gauche if (errors > 5) g.drawLine(250, 200, 280, 250); // Jambe droite // VISAGE TRISTE quand il meurt : if (errors > 6) { g.drawLine(235, 95, 245, 95); // Œil gauche } if (errors > 7) { g.drawLine(255, 95, 265, 95); // Œil droit } if (errors > 8) { // Bouche TRISTE (arc vers le bas) g.drawArc(235, 110, 30, 15, 0, 180); } } }