// Hands.java // 時計の針 // Copyright (C) 1996, 1997 Y.Nagatani // nagatani@eken.phys.nagoya-u.ac.jp import Poly; import java.applet.Applet; import java.awt.*; import java.util.Date; public class Hands extends Applet { public Poly handSec, handMin, handHour, dot; public void init () { super.init (); int xSize = this.size().width, ySize = this.size().height; handSec = new Poly (this, xSize, ySize, 4); handMin = new Poly (this, xSize, ySize, 3); handHour = new Poly (this, xSize, ySize, 3); handSec.setForm (0, -0.01, 1.0); handSec.setForm (1, +0.01, 1.0); handSec.setForm (2, +0.01, 0.0); handSec.setForm (3, -0.01, 0.0); handSec.setTranslate (0.5, 0.5); handMin.setForm (0, 0.0, 1.0); handMin.setForm (1, +0.1, -0.1); handMin.setForm (2, -0.1, -0.1); handMin.setTranslate (0.5, 0.5); handHour.setForm (0, 0.0, 1.0); handHour.setForm (1, +0.2, -0.1); handHour.setForm (2, -0.2, -0.1); handHour.setTranslate (0.5, 0.5); handSec.setColor (Color.white); handMin.setColor (Color.blue); handHour.setColor (Color.red); handSec.setScale (0.5); handMin.setScale (0.45); handHour.setScale (0.3); dot = new Poly (this, xSize, ySize, 3); dot.setScale (0.1); dot.setColor (Color.green); Color colorSec = getColorParameter("sec"), colorMin = getColorParameter("min"), colorHour = getColorParameter("hour"), colorDot = getColorParameter("dot"); if (colorSec != null) handSec.setColor (colorSec); if (colorMin != null) handMin.setColor (colorMin); if (colorHour != null) handHour.setColor (colorHour); if (colorDot != null) dot.setColor (colorDot); Color bg = getColorParameter("bgcolor"); if (bg != null) this.setBackground (bg); } public void paint (Graphics g) { g.setColor (getBackground()); g.fillRect (0, 0, size().width, size().height); g.setColor (getForeground()); for (int n = 0 ; n < 12 ; n++) { double arg = Math.PI/2 - 2.0*Math.PI * n / 12; dot.setTranslate (0.5 + 0.45 * Math.cos (arg), 0.5 - 0.45 * Math.sin (arg)); dot.setRotate (Math.PI/6 - 2.0*Math.PI * n / 12); dot.paint (g); } setParameters (); handHour.paint (g); handMin.paint (g); handSec.paint (g); } public void setParameters () { Date date = new Date(); int nHour = date.getHours(); int nMin = date.getMinutes(); int nSec = date.getSeconds(); handSec.setRotate (Math.PI - 2.0*Math.PI * nSec / 60); handMin.setRotate (Math.PI - 2.0*Math.PI * (60*nMin + nSec) / 60 / 60); handHour.setRotate (Math.PI - 2.0*Math.PI * (60*nHour + nMin) / 60 / 12); } public Color getColorParameter (String name) { String value = getParameter (name); int nColor; try {nColor = Integer.parseInt (value, 16);} catch (NumberFormatException e) { return null; } return new Color (nColor); } public int getIntParameter (String Command) throws NumberFormatException { String Contents = getParameter (Command); return Integer.parseInt (Contents); } public String[][] getParameterInfo () { String info[][] = { {"sec", "rrggbb (hexadecimal color value)", "second color"}, {"min", "rrggbb (hexadecimal color value)", "minute color"}, {"hour", "rrggbb (hexadecimal color value)", "hour color"}, {"dot", "rrggbb (hexadecimal color value)", "dots color"}, {"bgcolor", "rrggbb (hexadecimal color value)", "background color"} }; return info; } public String getAppletInfo () { return "Hands (a part for JClock)\n" + "Copyright(C) 1996, 1997 Y.nagatani\n" + "nagatani@eken.phys.nagoya-u.ac.jp"; } }