dcyde

ebic phail

Nov 20th, 2018
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.16 KB | None | 0 0
  1. package sample;
  2.  
  3. import javafx.application.Application;
  4. import javafx.scene.Scene;
  5. import javafx.scene.image.Image;
  6. import javafx.scene.image.ImageView;
  7. import javafx.scene.layout.HBox;
  8. import javafx.scene.layout.VBox;
  9. import javafx.stage.Stage;
  10.  
  11. import java.io.FileInputStream;
  12. import java.io.FileNotFoundException;
  13. import java.time.LocalTime;
  14. import java.time.format.DateTimeFormatter;
  15.  
  16. public class Main extends Application {
  17.  
  18. Image[] images;
  19.  
  20. {
  21. try {
  22. images = new Image[]{ new Image(new FileInputStream("D:\\0.png")), new Image(new FileInputStream("D:\\1.png")) };
  23. } catch (FileNotFoundException e) {
  24. e.printStackTrace();
  25. }
  26. }
  27.  
  28. ImageView[] hourFirst = new ImageView[2];
  29. ImageView[] hourSecond = new ImageView[4];
  30.  
  31. ImageView[] minuteFirst = new ImageView[4];
  32. ImageView[] minuteSecond = new ImageView[4];
  33.  
  34. ImageView[] secondFirst = new ImageView[4];
  35. ImageView[] secondSecond = new ImageView[4];
  36.  
  37. @Override
  38. public void start(Stage primaryStage) throws Exception {
  39.  
  40. HBox hBox = new HBox();
  41. hBox.getChildren().add(getHoursHBox());
  42. hBox.getChildren().add(getMinutesHBox());
  43. hBox.getChildren().add(getSecondsHBox());
  44.  
  45. primaryStage.setScene(new Scene(hBox));
  46. primaryStage.show();
  47.  
  48. boolean f = true;
  49.  
  50. while(f) {
  51.  
  52. Thread.sleep(1000);
  53.  
  54. String[] time = LocalTime.now().format(DateTimeFormatter.ofPattern("hh:mm:ss")).split(":");
  55.  
  56. int[] hours = getHours(Integer.valueOf(time[0]));
  57. for (int i = 0; i < hours.length ; i++) {
  58.  
  59. if(i <= 1) {
  60.  
  61. if(hours[i] == 0) { hourFirst[i].setImage(images[0]); } else { hourFirst[i].setImage(images[1]); }
  62.  
  63. } else {
  64.  
  65. if(hours[i] == 0) { hourSecond[i-2].setImage(images[0]); } else { hourSecond[i-2].setImage(images[1]); }
  66.  
  67. }
  68.  
  69. }
  70.  
  71. int[] minutes = getMinutesAndSeconds(Integer.valueOf(time[1]));
  72. for (int i = 0; i < minutes.length ; i++) {
  73.  
  74. if(i <= 3) {
  75.  
  76. if(minutes[i] == 0) { minuteFirst[i].setImage(images[0]); } else { minuteFirst[i].setImage(images[1]); }
  77.  
  78. } else {
  79.  
  80. if(minutes[i] == 0) { minuteSecond[i-4].setImage(images[0]); } else { minuteSecond[i-4].setImage(images[1]); }
  81.  
  82. }
  83.  
  84. }
  85.  
  86. int[] seconds = getMinutesAndSeconds(Integer.valueOf(time[2]));
  87. for (int i = 0; i < seconds.length ; i++) {
  88.  
  89. if(i <= 3) {
  90.  
  91. if(seconds[i] == 0) { secondFirst[i].setImage(images[0]); } else { secondFirst[i].setImage(images[1]); }
  92.  
  93. } else {
  94.  
  95. if(seconds[i] == 0) { secondSecond[i-4].setImage(images[0]); } else { secondSecond[i-4].setImage(images[1]); }
  96.  
  97. }
  98.  
  99. }
  100.  
  101. Thread.sleep(1000);
  102.  
  103. }
  104.  
  105. }
  106.  
  107. private HBox getHoursHBox() {
  108.  
  109. VBox vBoxFirstDigit = new VBox();
  110.  
  111. for(int i = 0 ; i < hourFirst.length ; i++) {
  112.  
  113. hourFirst[i] = new ImageView();
  114. hourFirst[i].setImage(images[0]);
  115. vBoxFirstDigit.getChildren().add(hourFirst[i]);
  116.  
  117. }
  118.  
  119. VBox vBoxSecondDigit = new VBox();
  120.  
  121. for(int i = 0 ; i < hourSecond.length ; i++) {
  122.  
  123. hourSecond[i] = new ImageView();
  124. hourSecond[i].setImage(images[0]);
  125. vBoxSecondDigit.getChildren().add(hourSecond[i]);
  126.  
  127. }
  128.  
  129. HBox hBox = new HBox();
  130. hBox.getChildren().add(vBoxFirstDigit);
  131. hBox.getChildren().add(vBoxSecondDigit);
  132.  
  133. return hBox;
  134.  
  135. }
  136.  
  137. private HBox getMinutesHBox() {
  138.  
  139. VBox vBoxFirstDigit = new VBox();
  140.  
  141. for(int i = 0 ; i < minuteFirst.length ; i++) {
  142.  
  143. minuteFirst[i] = new ImageView();
  144. minuteFirst[i].setImage(images[0]);
  145. vBoxFirstDigit.getChildren().add(minuteFirst[i]);
  146.  
  147. }
  148.  
  149. VBox vBoxSecondDigit = new VBox();
  150.  
  151. for(int i = 0 ; i < minuteSecond.length ; i++) {
  152.  
  153. minuteSecond[i] = new ImageView();
  154. minuteSecond[i].setImage(images[0]);
  155. vBoxSecondDigit.getChildren().add(minuteSecond[i]);
  156.  
  157. }
  158.  
  159. HBox hBox = new HBox();
  160. hBox.getChildren().add(vBoxFirstDigit);
  161. hBox.getChildren().add(vBoxSecondDigit);
  162.  
  163. return hBox;
  164.  
  165. }
  166.  
  167. private HBox getSecondsHBox() {
  168.  
  169. VBox vBoxFirstDigit = new VBox();
  170.  
  171. for(int i = 0 ; i < secondFirst.length ; i++) {
  172.  
  173. secondFirst[i] = new ImageView();
  174. secondFirst[i].setImage(images[0]);
  175. vBoxFirstDigit.getChildren().add(secondFirst[i]);
  176.  
  177. }
  178.  
  179. VBox vBoxSecondDigit = new VBox();
  180.  
  181. for(int i = 0 ; i < secondSecond.length ; i++) {
  182.  
  183. secondSecond[i] = new ImageView();
  184. secondSecond[i].setImage(images[0]);
  185. vBoxSecondDigit.getChildren().add(secondSecond[i]);
  186.  
  187. }
  188.  
  189. HBox hBox = new HBox();
  190. hBox.getChildren().add(vBoxFirstDigit);
  191. hBox.getChildren().add(vBoxSecondDigit);
  192.  
  193. return hBox;
  194.  
  195. }
  196.  
  197. private int[] getHours(int hours) {
  198.  
  199. int[] powerArray = {8, 4, 2, 1}, binaryHours = new int[6];
  200.  
  201. if(hours / 10 == 0) {
  202.  
  203. binaryHours[0] = 0;
  204. binaryHours[1] = 0;
  205.  
  206. for(int i = 0 ; i < powerArray.length ; i++) {
  207.  
  208. if(powerArray[i] <= hours) {
  209.  
  210. binaryHours[i+2] = 1;
  211. hours =- powerArray[i];
  212.  
  213. } else {
  214.  
  215. binaryHours[i+2] = 0;
  216.  
  217. }
  218.  
  219. }
  220.  
  221. } else {
  222.  
  223. int firstDigit = hours / 10;
  224. int lastDigit = hours % 10;
  225.  
  226. switch(firstDigit) {
  227.  
  228. case 1:
  229. binaryHours[0] = 0;
  230. binaryHours[1] = 1;
  231. break;
  232.  
  233. case 2:
  234. binaryHours[0] = 1;
  235. binaryHours[1] = 0;
  236. break;
  237.  
  238. }
  239.  
  240. for(int i = 0 ; i < powerArray.length ; i++) {
  241.  
  242. if(powerArray[i] <= lastDigit) {
  243.  
  244. binaryHours[i+2] = 1;
  245. lastDigit =- powerArray[i];
  246.  
  247. } else {
  248.  
  249. binaryHours[i+2] = 0;
  250.  
  251. }
  252.  
  253. }
  254.  
  255. }
  256.  
  257. return binaryHours;
  258. }
  259.  
  260. private int[] getMinutesAndSeconds(int minutesOrSeconds) {
  261.  
  262. int[] powerArray = {8, 4, 2, 1}, binaryMinutesOrSeconds = new int[8];
  263.  
  264. if(minutesOrSeconds / 10 == 0) {
  265.  
  266. binaryMinutesOrSeconds[0] = 0;
  267. binaryMinutesOrSeconds[1] = 0;
  268. binaryMinutesOrSeconds[2] = 0;
  269. binaryMinutesOrSeconds[3] = 0;
  270.  
  271. for(int i = 0 ; i < powerArray.length ; i++) {
  272.  
  273. if(powerArray[i] <= minutesOrSeconds) {
  274.  
  275. binaryMinutesOrSeconds[i+4] = 1;
  276. minutesOrSeconds =- powerArray[i];
  277.  
  278. } else {
  279.  
  280. binaryMinutesOrSeconds[i+4] = 0;
  281.  
  282. }
  283.  
  284. }
  285.  
  286. } else {
  287.  
  288. int firstDigit = minutesOrSeconds / 10;
  289. int lastDigit = minutesOrSeconds % 10;
  290.  
  291. for(int i = 0 ; i < powerArray.length ; i++) {
  292.  
  293. if(powerArray[i] <= firstDigit) {
  294.  
  295. binaryMinutesOrSeconds[i] = 1;
  296. firstDigit =- powerArray[i];
  297.  
  298. } else {
  299.  
  300. binaryMinutesOrSeconds[i] = 0;
  301.  
  302. }
  303.  
  304. }
  305.  
  306. for(int i = 0 ; i < powerArray.length ; i++) {
  307.  
  308. if(powerArray[i] <= lastDigit) {
  309.  
  310. binaryMinutesOrSeconds[i+4] = 1;
  311. lastDigit =- powerArray[i];
  312.  
  313. } else {
  314.  
  315. binaryMinutesOrSeconds[i+4] = 0;
  316.  
  317. }
  318.  
  319. }
  320.  
  321. }
  322.  
  323. return binaryMinutesOrSeconds;
  324. }
  325.  
  326.  
  327. public static void main(String[] args) {
  328. launch(args);
  329. }
  330. }
Add Comment
Please, Sign In to add comment