import java.awt.*; import javax.swing.*; import java.awt.geom.*; public class JavaMan2 extends JApplet { float height; float width; Color bodyColor = Color.blue; Color hatColor = Color.magenta; public void init() { setBackground(Color.yellow); String bgParam = getParameter("BGCOLOR"); if (bgParam != null) setBackground(hexToColor(bgParam)); String bodyParam = getParameter("BODYCOLOR"); if (bodyParam != null) bodyColor = hexToColor(bodyParam); String hatParam = getParameter("HATCOLOR"); if (hatParam != null) hatColor = hexToColor(hatParam); } public Color hexToColor(String hexVal) { String redVal = hexVal.substring(0, 2); String greenVal = hexVal.substring(2, 4); String blueVal = hexVal.substring(4, 6); int red = Integer.parseInt(redVal, 16); int green = Integer.parseInt(greenVal, 16); int blue = Integer.parseInt(blueVal, 16); Color newColor = new Color(red, green, blue); return newColor; } public void paint(Graphics screen) { Graphics2D screen2D = (Graphics2D) screen; height = (float) getSize().height; width = (float) getSize().width; screen2D.setColor(Color.black); RoundRectangle2D.Float border = new RoundRectangle2D.Float( 10F, 10F, width-20, height-20, 15F, 15F); screen2D.draw(border); screen2D.setColor(Color.gray); Rectangle2D.Float box = new Rectangle2D.Float( 200F, 90F, 100F, 100F); screen2D.fill(box); screen2D.setColor(bodyColor); for (int x = 200; x < 300; x += 5) for (int y = 90; y < 190; y += 5) { Rectangle2D.Float r = new Rectangle2D.Float( x, y, 5, 5); screen2D.draw(r); } screen2D.setColor(Color.black); Line2D.Float ln1 = new Line2D.Float(200F, 110F, 170F, 115F); Line2D.Float ln2 = new Line2D.Float(170F, 115F, 160F, 90F); Line2D.Float ln3 = new Line2D.Float(160F, 90F, 150F, 94F); Line2D.Float ln4 = new Line2D.Float(160F, 90F, 153F, 85F); Line2D.Float ln5 = new Line2D.Float(160F, 90F, 158F, 83F); Line2D.Float ln6 = new Line2D.Float(160F, 90F, 163F, 84F); screen2D.draw(ln1); screen2D.draw(ln2); screen2D.draw(ln3); screen2D.draw(ln4); screen2D.draw(ln5); screen2D.draw(ln6); screen2D.setColor(Color.white); Ellipse2D.Float head = new Ellipse2D.Float(220F, 30F, 60F, 60F); screen2D.fill(head); screen2D.setColor(Color.green); Ellipse2D.Float leftEye = new Ellipse2D.Float(245F, 45F, 5F, 5F); Ellipse2D.Float rightEye = new Ellipse2D.Float(255F, 45F, 5F, 5F); screen2D.fill(leftEye); screen2D.fill(rightEye); screen2D.setColor(Color.black); Rectangle2D.Float mouth = new Rectangle2D.Float(245F, 65F, 15F, 15F); screen2D.fill(mouth); screen2D.setColor(hatColor); GeneralPath chapeau = new GeneralPath(); chapeau.moveTo(205F, 43F); chapeau.lineTo(305F, 40F); chapeau.lineTo(240F, 15F); chapeau.lineTo(205F, 43F); chapeau.closePath(); screen2D.fill(chapeau); } }