Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package analogclock;
  7.  
  8. import java.awt.Font;
  9. import java.util.Calendar;
  10. import java.util.GregorianCalendar;
  11. import javafx.application.Application;
  12. import javafx.event.ActionEvent;
  13. import javafx.event.EventHandler;
  14. import javafx.scene.Scene;
  15. import javafx.scene.control.Button;
  16. import javafx.scene.layout.*;
  17. import javafx.scene.paint.Color;
  18. import javafx.stage.Stage;
  19. import javafx.scene.*;
  20. import javafx.scene.shape.*;
  21. import javafx.scene.paint.*;
  22. import javafx.scene.canvas.*;
  23. import javafx.scene.control.*;
  24. import javafx.scene.transform.Rotate;
  25.  
  26. /**
  27. *
  28. * @author KubaK
  29. */
  30.  
  31.  
  32.  
  33. public class AnalogClock extends Application {
  34.  
  35. class ResizableClock extends Canvas {
  36.  
  37. public ResizableClock() {
  38. // Redraw canvas when size changes.
  39. widthProperty().addListener(evt -> draw());
  40. heightProperty().addListener(evt -> draw());
  41. }
  42.  
  43.  
  44.  
  45. //Calendar calendar = GregorianCalendar.getInstance();
  46.  
  47. private void draw() {
  48.  
  49. double height = getHeight() - 25;
  50. double width = getWidth();
  51. //final double seedSecondDegrees = calendar.get(Calendar.SECOND) * (360 / 60);
  52. //final double seedMinuteDegrees = (calendar.get(Calendar.MINUTE) + seedSecondDegrees / 360.0) * (360 / 60);
  53. // final double seedHourDegrees = (calendar.get(Calendar.HOUR) + seedMinuteDegrees / 360.0) * (360 / 12) ;
  54.  
  55. GraphicsContext gc = getGraphicsContext2D();
  56. gc.clearRect(0, 0, width, height);
  57. // TŁO
  58. gc.setFill(Color.BLACK);
  59. gc.fillRect(0,0,height, height);
  60. // TARCZA ZEGARA
  61. gc.setFill(Color.WHITE);
  62. gc.fillOval(20, 20, height - 40, height - 40);
  63. // WSKAZOWKA GODZINOWA
  64. Line hourHand = new Line();
  65. hourHand.setStartX((getHeight()-25)/2);
  66. hourHand.setStartY((getHeight()-25)/2);
  67. hourHand.setEndX((getHeight()-25)/2);
  68. hourHand.setEndY((getHeight()-25)/4);
  69. gc.setStroke(Color.CORNFLOWERBLUE);
  70. gc.setLineWidth(20);
  71.  
  72. hourHand.getTransforms().addAll(new Rotate(200, hourHand.getStartX(), hourHand.getStartY()));
  73. gc.strokeLine(hourHand.getStartX(),hourHand.getStartY(),hourHand.getEndX(),hourHand.getEndY());
  74.  
  75. Rectangle rec = new Rectangle(50, 50, 200, 200);
  76. rec.setStroke(Color.BLACK);
  77. rec.setFill(Color.WHITE);
  78.  
  79.  
  80.  
  81. // KROPKA NA ŚRODKU
  82. gc.setFill(Color.BLACK);
  83. gc.fillOval(height/2 - 15, height/2 - 15, 30, 30);
  84.  
  85.  
  86.  
  87. }
  88.  
  89. @Override
  90. public boolean isResizable() {
  91. return true;
  92. }
  93.  
  94. @Override
  95. public double prefWidth(double height) {
  96. return getHeight() - 25; // zeby zachowalo ratio, bo obszar zegaru to heightxheight, wczesniej wypychalo tablice w prawo
  97. }
  98.  
  99. @Override
  100. public double prefHeight(double width) {
  101. return getHeight();
  102. }
  103. }
  104.  
  105.  
  106.  
  107. @Override
  108. public void start(Stage primaryStage) {
  109. primaryStage.setTitle("Analog Clock - Jakub Krech");
  110. BorderPane root = new BorderPane();
  111.  
  112. Scene scene = new Scene(root, 800, 600, Color.BLUE);
  113.  
  114. // MENU
  115. MenuBar menu = new MenuBar();
  116. Menu menuFile = new Menu("Program");
  117. menuFile.getItems().add(new MenuItem("Zamknij"));
  118. Menu menuEdit = new Menu("Budzik");
  119. menuEdit.getItems().add(new MenuItem("Dodaj alarm"));
  120. menuEdit.getItems().add(new MenuItem("Wyczyść alarmy"));
  121. Menu menuView = new Menu("O autorze");
  122. menu.getMenus().addAll(menuFile, menuEdit, menuView);
  123. root.setTop(menu);
  124.  
  125. //CANVAS
  126. ResizableClock canvas = new ResizableClock();
  127. canvas.widthProperty().bind(root.widthProperty());
  128. canvas.heightProperty().bind(root.heightProperty());
  129.  
  130.  
  131. root.setLeft(canvas);
  132.  
  133.  
  134. //TABLE
  135. TableView table = new TableView();
  136. table.setPrefWidth(225);
  137. table.setPrefHeight(600);
  138. table.setEditable(false);
  139. TableColumn nazwa = new TableColumn("Nazwa");
  140. TableColumn godzina = new TableColumn("Godzina");
  141. nazwa.prefWidthProperty().bind(table.widthProperty().multiply(0.5));
  142. nazwa.setResizable(false);
  143. godzina.prefWidthProperty().bind(table.widthProperty().multiply(0.5));
  144. godzina.setResizable(false);
  145.  
  146. table.getColumns().addAll(nazwa, godzina);
  147.  
  148. root.setRight(table);
  149.  
  150.  
  151.  
  152.  
  153.  
  154. primaryStage.setScene(scene);
  155. primaryStage.show();
  156. }
  157.  
  158. /**
  159. * @param args the command line arguments
  160. */
  161. public static void main(String[] args) {
  162. launch(args);
  163. }
  164.  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement