import javax.swing.*; import java.awt.*; /** * La classe Dessin gère uniquement le dessin du pendu * * @version 1.0 * @author Adrien * Date : 08-10-2025 * Licence : */ public class Dessin extends JPanel { // --- Constructeur --- public Dessin() { // Taille préférée pour s'intégrer dans Fenetre setPreferredSize(new Dimension(600, 350)); setBackground(new Color(245, 245, 245)); } // --- Dessin principal --- @Override protected void paintComponent(Graphics graphics) { super.paintComponent(graphics); // Anti-aliasing pour des traits plus doux Graphics2D graphics2D = (Graphics2D) graphics.create(); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.setStroke(new BasicStroke(3f)); graphics2D.setColor(Color.DARK_GRAY); // Repères et proportions int width = getWidth(); int height = getHeight(); int marginPixels = Math.min(width, height) / 12; // marge proportionnelle // Potence : socle int baseYCoordinate = height - marginPixels; graphics2D.drawLine(marginPixels, baseYCoordinate, width / 2, baseYCoordinate); // Montant vertical int postXCoordinate = marginPixels + (width / 12); graphics2D.drawLine(postXCoordinate, baseYCoordinate, postXCoordinate, marginPixels); // Traverse horizontale int beamLength = width / 3; graphics2D.drawLine(postXCoordinate, marginPixels, postXCoordinate + beamLength, marginPixels); // Renfort diagonal graphics2D.drawLine(postXCoordinate, marginPixels + height / 10, postXCoordinate + width / 12, marginPixels); // Corde int ropeXCoordinate = postXCoordinate + beamLength; int ropeTopYCoordinate = marginPixels; int ropeBottomYCoordinate = marginPixels + height / 12; graphics2D.drawLine(ropeXCoordinate, ropeTopYCoordinate, ropeXCoordinate, ropeBottomYCoordinate); // Personnage : tête int headRadiusPixels = Math.min(width, height) / 16; int headCenterX = ropeXCoordinate; int headCenterY = ropeBottomYCoordinate + headRadiusPixels; graphics2D.drawOval(headCenterX - headRadiusPixels, headCenterY - headRadiusPixels, headRadiusPixels * 2, headRadiusPixels * 2); // Corps int bodyTopYCoordinate = headCenterY + headRadiusPixels; int bodyBottomYCoordinate = bodyTopYCoordinate + height / 6; graphics2D.drawLine(headCenterX, bodyTopYCoordinate, headCenterX, bodyBottomYCoordinate); // Bras int armSpanPixels = width / 10; int shouldersYCoordinate = bodyTopYCoordinate + height / 24; graphics2D.drawLine(headCenterX, shouldersYCoordinate, headCenterX - armSpanPixels, shouldersYCoordinate + height / 20); graphics2D.drawLine(headCenterX, shouldersYCoordinate, headCenterX + armSpanPixels, shouldersYCoordinate + height / 20); // Jambes int legSpanPixels = width / 12; graphics2D.drawLine(headCenterX, bodyBottomYCoordinate, headCenterX - legSpanPixels, bodyBottomYCoordinate + height / 8); graphics2D.drawLine(headCenterX, bodyBottomYCoordinate, headCenterX + legSpanPixels, bodyBottomYCoordinate + height / 8); graphics2D.dispose(); } // Affichage @Override public String toString() { return ""; } }