// import java.awt.*; import java.applet.*; import java.io.*; import java.util.*; public class p5 extends Applet implements Runnable { Calendar cal; String month, day, hour, min, sec; String now; int mon, d, h, m, s; double theta_h, theta_m, theta_s; char part; private Thread th; public void init(){ now = ""; part = ' '; th = new Thread(this); th.start(); } public void run(){ while(true){ cal = Calendar.getInstance(); mon = cal.get(Calendar.MONTH) + 1; d = cal.get(Calendar.DAY_OF_MONTH); h = cal.get(Calendar.HOUR_OF_DAY); m = cal.get(Calendar.MINUTE); s = cal.get(Calendar.SECOND); if(mon<10) month = " " + Integer.toString(mon); else month = Integer.toString(mon); if(d<10) day = " " + Integer.toString(d); else day = Integer.toString(d); hour = Integer.toString(h); min = Integer.toString(m); sec = Integer.toString(s); if(hour.length()!=2) hour = '0' + hour; if(min.length()!=2) min = '0' + min; if(sec.length()!=2) sec = '0' + sec; if(part == ' ') part = ':'; else part = ' '; theta_h = (-30 * h) + (-0.5 * m) +180; theta_m = -6 * m + 180; theta_s = -6 * s + 180; now = hour + part + min + part + sec; System.out.print(now + "\r"); repaint(); try{ th.sleep(1000); }catch (Exception e) {} } } public void paint(Graphics g){ String str; g.setColor(Color.white); g.fillRect(0,0,200,200); g.setColor(Color.black); g.drawOval(20,20,160,160); g.setFont(new Font("MS Gothic", Font.PLAIN, 11)); g.setColor(Color.black); g.fillOval(98,98,4,4); // g.drawLine(100,0,100,200); // g.drawLine(0,100,200,100); g.setColor(Color.black); for(int i=1;i<=12;i++){ str = Integer.toString(i); if(i/10==0) g.drawString(str,(x_point(68,30*i-90)-3),(y_point(68,30*i-90)+5)); else g.drawString(str,(x_point(68,30*i-90)-6),(y_point(68,30*i-90)+5)); g.drawLine((x_point(75,30*i-90)),(y_point(75,30*i-90)),(x_point(78,30*i-90)),(y_point(78,30*i-90))); } g.setColor(Color.black); g.drawString(now, 77, 16); g.setColor(Color.gray); g.fillRect(80,135,40,20); g.setColor(Color.white); g.setFont(new Font("Times New Roman", Font.BOLD, 15)); g.drawString(month + "/" + day, 82, 150); g.setColor(Color.black); g.drawLine(100,100,y_point(75,theta_s),x_point(75,theta_s)); g.drawLine(100,100,y_point(20,theta_s + 180),x_point(20,theta_s + 180)); g.drawLine(100,100,y_point(72,theta_m),x_point(72,theta_m)); g.drawLine(100,100,y_point(50,theta_h),x_point(50,theta_h)); g.setFont(new Font("Times New Roman", Font.ITALIC, 10)); g.setColor(Color.blue); g.drawString("Made by shinsoku", 50, 195); } public int y_point(double rr, double tt){ int high = 0; double angle = tt * Math.PI / 180.0; high = 100 + (int)(rr * Math.sin(angle)); return high; } public int x_point(double rr, double tt){ int wide = 0; double angle = tt * Math.PI / 180.0; wide = 100 + (int)(rr * Math.cos(angle)); return wide; } }