document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.util.*;
  2. import java.awt.*;
  3. import java.applet.*;
  4. import java.text.*;
  5. /**
  6. * Program Jam analog
  7. *
  8. * @author Ifanu Antoni
  9. * @version
  10. */
  11. public class Clock extends Applet implements Runnable {
  12. private volatile Thread timer;
  13. private int lastxs, lastys, lastxm, lastym, lastxh, lastyh;
  14. private SimpleDateFormat formatter;
  15. private String lastdate;
  16. private Font clockFaceFont;
  17. private Date currentDate;
  18. private Color handColor;
  19. private Color numberColor;
  20. private int xcenter = 80, ycenter = 55;
  21.  
  22. public void init()
  23. {
  24. int x,y;
  25. lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0;
  26. formatter = new SimpleDateFormat ("EEE MMM dd hh:mm:ss yyyy",
  27. Locale.getDefault());
  28. currentDate = new Date();
  29. lastdate = formatter.format(currentDate);
  30. clockFaceFont = new Font("Serif", Font.PLAIN, 14);
  31. handColor = Color.green;
  32. numberColor = Color.black;
  33.  
  34. try {
  35. setBackground(new Color(Integer.parseInt(getParameter("bgcolor"), 16)));
  36. }
  37. catch (NullPointerException e) { }
  38. catch (NumberFormatException e) { }
  39. try {
  40. handColor = new Color(Integer.parseInt(getParameter("fgcolor1"), 16));
  41. }
  42. catch (NullPointerException e) { }
  43. catch (NumberFormatException e) { }
  44. try {
  45. numberColor = new Color(Integer.parseInt(getParameter("fgcolor2"), 16));
  46. }
  47. catch (NullPointerException e) { }
  48. catch (NumberFormatException e) { }
  49. resize(300,300); // Set clock window size
  50. }
  51. public void update(Graphics g)
  52. {
  53. int xh, yh, xm, ym, xs, ys;
  54. int s = 0, m = 10, h = 10;
  55. String today;
  56.  
  57. currentDate = new Date();
  58.  
  59. formatter.applyPattern("s");
  60. try {
  61. s = Integer.parseInt(formatter.format(currentDate));
  62. } catch (NumberFormatException n) {
  63. s = 0;
  64. }
  65. formatter.applyPattern("m");
  66. try {
  67. m = Integer.parseInt(formatter.format(currentDate));
  68. } catch (NumberFormatException n) {
  69. m = 10;
  70. }
  71. formatter.applyPattern("h");
  72. try {
  73. h = Integer.parseInt(formatter.format(currentDate));
  74. } catch (NumberFormatException n) {
  75. h = 10;
  76. }
  77.  
  78. // Set position of the ends of the hands
  79. xs = (int) (Math.cos(s * Math.PI / 30 - Math.PI / 2) * 45 + xcenter);
  80. ys = (int) (Math.sin(s * Math.PI / 30 - Math.PI / 2) * 45 + ycenter);
  81. xm = (int) (Math.cos(m * Math.PI / 30 - Math.PI / 2) * 40 + xcenter);
  82. ym = (int) (Math.sin(m * Math.PI / 30 - Math.PI / 2) * 40 + ycenter);
  83. xh = (int) (Math.cos((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30 + xcenter);
  84. yh = (int) (Math.sin((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30 + ycenter);
  85.  
  86. // Get the date to print at the bottom
  87. formatter.applyPattern("EEE MMM dd HH:mm:ss yyyy");
  88. today = formatter.format(currentDate);
  89.  
  90. g.setFont(clockFaceFont);
  91. // Erase if necessary
  92. g.setColor(getBackground());
  93. if (xs != lastxs || ys != lastys) {
  94. g.drawLine(xcenter, ycenter, lastxs, lastys);
  95. g.drawString(lastdate, 5, 125);
  96. }
  97. if (xm != lastxm || ym != lastym) {
  98. g.drawLine(xcenter, ycenter-1, lastxm, lastym);
  99. g.drawLine(xcenter-1, ycenter, lastxm, lastym);
  100. }
  101. if (xh != lastxh || yh != lastyh) {
  102. g.drawLine(xcenter, ycenter-1, lastxh, lastyh);
  103. g.drawLine(xcenter-1, ycenter, lastxh, lastyh);
  104. }
  105.  
  106. // Draw date and hands
  107. g.setColor(numberColor);
  108. g.drawString(today, 5, 125);
  109. g.drawLine(xcenter, ycenter, xs, ys);
  110. g.setColor(handColor);
  111. g.drawLine(xcenter, ycenter-1, xm, ym);
  112. g.drawLine(xcenter-1, ycenter, xm, ym);
  113. g.drawLine(xcenter, ycenter-1, xh, yh);
  114. g.drawLine(xcenter-1, ycenter, xh, yh);
  115. lastxs = xs; lastys = ys;
  116. lastxm = xm; lastym = ym;
  117. lastxh = xh; lastyh = yh;
  118. lastdate = today;
  119. currentDate = null;
  120. }
  121. // Paint is the main part of the program
  122. public void paint(Graphics g)
  123. {
  124. g.setFont(clockFaceFont);
  125. // Draw the circle and numbers
  126. g.setColor(handColor);
  127. g.drawArc(xcenter-50, ycenter-50, 100, 100, 0, 360);
  128. g.setColor(numberColor);
  129. g.drawString("9", xcenter-45, ycenter+3);
  130. g.drawString("3", xcenter+40, ycenter+3);
  131. g.drawString("12", xcenter-5, ycenter-37);
  132. g.drawString("6", xcenter-3, ycenter+45);
  133.  
  134. // Draw date and hands
  135. g.setColor(numberColor);
  136. g.drawString(lastdate, 5, 125);
  137. g.drawLine(xcenter, ycenter, lastxs, lastys);
  138. g.setColor(handColor);
  139. g.drawLine(xcenter, ycenter-1, lastxm, lastym);
  140. g.drawLine(xcenter-1, ycenter, lastxm, lastym);
  141. g.drawLine(xcenter, ycenter-1, lastxh, lastyh);
  142. g.drawLine(xcenter-1, ycenter, lastxh, lastyh);
  143. }
  144. public void start() {
  145. timer = new Thread(this);
  146. timer.start();
  147. }
  148. public void stop() {
  149. timer = null;
  150. }
  151. public void run() {
  152. Thread me = Thread.currentThread();
  153. while (timer == me) {
  154. try {
  155. Thread.currentThread().sleep(100);
  156. } catch (InterruptedException e) {
  157. }
  158. repaint();
  159. }
  160. }
  161. public String getAppletInfo() {
  162. return "Title: Jam \\n" + "Author: Ifanu Antoni, 2020 \\n" + "menampilkan jam analog";
  163. }
  164. public String[][] getParameterInfo() {
  165. String[][] info = {
  166. {"bgcolor", "hexadecimal RGB number", "Warna background adalah warna dari default browser."},
  167. {"fgcolor1", "hexadecimal RGB number", "Warna jarum pada jam adalah hijau."},
  168. {"fgcolor2", "hexadecimal RGB number", "Warna jarum detik dan angka pada jam adalah hitam."}
  169. };
  170. return info;
  171. }
  172. }
');