Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. package project1;
  2.  
  3. import javax.swing.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import static java.lang.System.load;
  7.  
  8. class mainPanel extends JPanel{
  9.  
  10. private MyTimerPanel p1;
  11. private MyTimerPanel p2;
  12. private MyTimerPanel p3;
  13.  
  14. public mainPanel(){
  15.  
  16. p1 = new MyTimerPanel();
  17. p2 = new MyTimerPanel();
  18. p3 = new MyTimerPanel();
  19.  
  20. add (p1);
  21. add (p2);
  22. add (p3);
  23.  
  24. }
  25.  
  26. }
  27.  
  28. public class MyTimerPanel extends JPanel{
  29.  
  30. private GeoCountDownTimer geoCountDownTimer;
  31.  
  32. private Timer javaTimer;
  33. private TimerListener timer;
  34.  
  35. private JLabel label;
  36. private JLabel output;
  37.  
  38. private JButton incDay;
  39. private JButton decDay;
  40. private JButton inc1;
  41. private JButton dec1;
  42. private JButton compare;
  43. private JButton load;
  44. private JButton save;
  45. private JButton Days2Go;
  46. private JButton equal;
  47. private JButton daysInFuture;
  48. private JButton start;
  49. private JButton stop;
  50. private JButton enter;
  51.  
  52. private JTextField value;
  53.  
  54. public MyTimerPanel(){
  55.  
  56. geoCountDownTimer = new GeoCountDownTimer();
  57.  
  58. timer = new TimerListener();
  59.  
  60. load = new JButton("Load Timer:");
  61. save = new JButton("Save Timer:");
  62. Days2Go = new JButton("Days to Go");
  63. equal = new JButton("Equal?");
  64. compare = new JButton("Compare to:");
  65. start = new JButton("Start");
  66. stop = new JButton("Stop");
  67. enter = new JButton("Enter");
  68. incDay = new JButton("Days to Increase");
  69. decDay = new JButton("Days to Decrease");
  70. inc1 = new JButton("+1 Day");
  71. dec1 = new JButton("-1 Day");
  72. daysInFuture = new JButton ("Days in Future");
  73.  
  74. output = new JLabel("Please enter a date in the text field and press enter.");
  75. label = new JLabel("xx/xx/xxxx");
  76.  
  77. value = new JTextField(" ");
  78.  
  79. add (daysInFuture);
  80. add (output);
  81. add (load);
  82. add (save);
  83. add (Days2Go);
  84. add (equal);
  85. add (compare);
  86. add (inc1);
  87. add (dec1);
  88. add (incDay);
  89. add (decDay);
  90. add (start);
  91. add (stop);
  92. add (enter);
  93.  
  94. add (new JLabel("Timer: "));
  95. add (label);
  96.  
  97. add (new JLabel("Input Timer: "));
  98. add (value);
  99.  
  100. start.addActionListener(new ButListener());
  101. stop.addActionListener(new ButListener());
  102. enter.addActionListener(new ButListener());
  103. incDay.addActionListener(new ButListener());
  104. decDay.addActionListener(new ButListener());
  105. load.addActionListener(new ButListener());
  106. save.addActionListener(new ButListener());
  107. Days2Go.addActionListener(new ButListener());
  108. equal.addActionListener(new ButListener());
  109. compare.addActionListener(new ButListener());
  110. inc1.addActionListener(new ButListener());
  111. dec1.addActionListener(new ButListener());
  112. daysInFuture.addActionListener(new ButListener());
  113.  
  114. // this calls timer object 10 times per second
  115. javaTimer = new Timer(1000, timer); // 1000 * 60 * 60 * 24
  116.  
  117. }
  118.  
  119. private class TimerListener implements ActionListener{
  120.  
  121. public void actionPerformed(ActionEvent e){
  122.  
  123. geoCountDownTimer.inc();
  124. label.setText(geoCountDownTimer.toDateString());
  125.  
  126. if (geoCountDownTimer.equals(new GeoCountDownTimer("1/1/2038"))){
  127. System.out.println ("Time is up!");
  128. javaTimer.stop();
  129.  
  130. }
  131.  
  132. }
  133.  
  134. }
  135.  
  136. private class ButListener implements ActionListener{
  137. public void actionPerformed(ActionEvent e)
  138. {
  139. if (start == e.getSource())
  140. javaTimer.start();
  141.  
  142. else if (inc1 == e.getSource()) {
  143. geoCountDownTimer.inc();
  144. label.setText(geoCountDownTimer.toDateString());
  145. }
  146.  
  147. else if (dec1 == e.getSource()) {
  148. geoCountDownTimer.dec();
  149. label.setText(geoCountDownTimer.toDateString());
  150. }
  151.  
  152. else if (stop == e.getSource()) {
  153. javaTimer.stop();
  154. label.setText(geoCountDownTimer.toDateString());
  155. }
  156.  
  157. else if (enter == e.getSource()) {
  158. geoCountDownTimer = new GeoCountDownTimer(value.getText().trim());
  159. label.setText(geoCountDownTimer.toDateString());
  160. }
  161.  
  162. else if (decDay == e.getSource()) {
  163. geoCountDownTimer.dec(Integer.parseInt(value.getText().trim()));
  164. label.setText(geoCountDownTimer.toDateString());
  165. }
  166.  
  167. else if (incDay == e.getSource()) {
  168. geoCountDownTimer.inc(Integer.parseInt(value.getText().trim()));
  169. label.setText(geoCountDownTimer.toDateString());
  170. }
  171.  
  172. else if (load == e.getSource()) {
  173. load(value.getText().trim());
  174. label.setText(geoCountDownTimer.toDateString());
  175. }
  176.  
  177. else if (save == e.getSource()) {
  178. geoCountDownTimer.save(value.getText().trim());
  179. label.setText(geoCountDownTimer.toDateString());
  180. }
  181.  
  182. else if (compare == e.getSource()) {
  183. GeoCountDownTimer s = new GeoCountDownTimer(label.getText());
  184. GeoCountDownTimer s1 = new GeoCountDownTimer(value.getText().trim());
  185.  
  186. if (s.compareTo(s1) == 1)
  187. output.setText("Your date is less than the Current Timer!");
  188. else if (s.compareTo(s1)==0)
  189. output.setText(("Your date is equal to the Current Timer!"));
  190. else if (s.compareTo(s1)==-1)
  191. output.setText("Your date is greater than the Current Timer!");
  192. else output.setText("Your date is invalid, please enter a date in the format 'xx/xx/xxxx'");
  193. }
  194.  
  195. else if(Days2Go == e.getSource()) {
  196. int temp = 0;
  197. temp = geoCountDownTimer.daysToGo(value.getText().trim());
  198. output.setText(temp + " days remaining!");
  199. }
  200.  
  201. else if(daysInFuture == e.getSource()) {
  202. GeoCountDownTimer temp = new GeoCountDownTimer(label.getText().trim());
  203. temp.daysInTheFuture(Integer.parseInt(value.getText().trim()));
  204. output.setText(temp.toDateString() + " is the date " + label.getText().trim() + " days in the future!");
  205. }
  206.  
  207. else if (equal == e.getSource()){
  208. GeoCountDownTimer s = new GeoCountDownTimer(label.getText());
  209. GeoCountDownTimer s1 = new GeoCountDownTimer(value.getText().trim());
  210. if (s.equals(s1))
  211. output.setText(("Your date is equal to the Current Timer!"));
  212. }
  213.  
  214. }
  215.  
  216. }
  217.  
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement