Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package analogclock;
- import java.awt.Font;
- import java.util.Calendar;
- import java.util.GregorianCalendar;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.*;
- import javafx.scene.paint.Color;
- import javafx.stage.Stage;
- import javafx.scene.*;
- import javafx.scene.shape.*;
- import javafx.scene.paint.*;
- import javafx.scene.canvas.*;
- import javafx.scene.control.*;
- import javafx.scene.transform.Rotate;
- /**
- *
- * @author KubaK
- */
- public class AnalogClock extends Application {
- class ResizableClock extends Canvas {
- public ResizableClock() {
- // Redraw canvas when size changes.
- widthProperty().addListener(evt -> draw());
- heightProperty().addListener(evt -> draw());
- }
- //Calendar calendar = GregorianCalendar.getInstance();
- private void draw() {
- double height = getHeight() - 25;
- double width = getWidth();
- //final double seedSecondDegrees = calendar.get(Calendar.SECOND) * (360 / 60);
- //final double seedMinuteDegrees = (calendar.get(Calendar.MINUTE) + seedSecondDegrees / 360.0) * (360 / 60);
- // final double seedHourDegrees = (calendar.get(Calendar.HOUR) + seedMinuteDegrees / 360.0) * (360 / 12) ;
- GraphicsContext gc = getGraphicsContext2D();
- gc.clearRect(0, 0, width, height);
- // TŁO
- gc.setFill(Color.BLACK);
- gc.fillRect(0,0,height, height);
- // TARCZA ZEGARA
- gc.setFill(Color.WHITE);
- gc.fillOval(20, 20, height - 40, height - 40);
- // WSKAZOWKA GODZINOWA
- Line hourHand = new Line();
- hourHand.setStartX((getHeight()-25)/2);
- hourHand.setStartY((getHeight()-25)/2);
- hourHand.setEndX((getHeight()-25)/2);
- hourHand.setEndY((getHeight()-25)/4);
- gc.setStroke(Color.CORNFLOWERBLUE);
- gc.setLineWidth(20);
- hourHand.getTransforms().addAll(new Rotate(200, hourHand.getStartX(), hourHand.getStartY()));
- gc.strokeLine(hourHand.getStartX(),hourHand.getStartY(),hourHand.getEndX(),hourHand.getEndY());
- Rectangle rec = new Rectangle(50, 50, 200, 200);
- rec.setStroke(Color.BLACK);
- rec.setFill(Color.WHITE);
- // KROPKA NA ŚRODKU
- gc.setFill(Color.BLACK);
- gc.fillOval(height/2 - 15, height/2 - 15, 30, 30);
- }
- @Override
- public boolean isResizable() {
- return true;
- }
- @Override
- public double prefWidth(double height) {
- return getHeight() - 25; // zeby zachowalo ratio, bo obszar zegaru to heightxheight, wczesniej wypychalo tablice w prawo
- }
- @Override
- public double prefHeight(double width) {
- return getHeight();
- }
- }
- @Override
- public void start(Stage primaryStage) {
- primaryStage.setTitle("Analog Clock - Jakub Krech");
- BorderPane root = new BorderPane();
- Scene scene = new Scene(root, 800, 600, Color.BLUE);
- // MENU
- MenuBar menu = new MenuBar();
- Menu menuFile = new Menu("Program");
- menuFile.getItems().add(new MenuItem("Zamknij"));
- Menu menuEdit = new Menu("Budzik");
- menuEdit.getItems().add(new MenuItem("Dodaj alarm"));
- menuEdit.getItems().add(new MenuItem("Wyczyść alarmy"));
- Menu menuView = new Menu("O autorze");
- menu.getMenus().addAll(menuFile, menuEdit, menuView);
- root.setTop(menu);
- //CANVAS
- ResizableClock canvas = new ResizableClock();
- canvas.widthProperty().bind(root.widthProperty());
- canvas.heightProperty().bind(root.heightProperty());
- root.setLeft(canvas);
- //TABLE
- TableView table = new TableView();
- table.setPrefWidth(225);
- table.setPrefHeight(600);
- table.setEditable(false);
- TableColumn nazwa = new TableColumn("Nazwa");
- TableColumn godzina = new TableColumn("Godzina");
- nazwa.prefWidthProperty().bind(table.widthProperty().multiply(0.5));
- nazwa.setResizable(false);
- godzina.prefWidthProperty().bind(table.widthProperty().multiply(0.5));
- godzina.setResizable(false);
- table.getColumns().addAll(nazwa, godzina);
- root.setRight(table);
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement