Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package application;
- import controller.controller;
- import java.awt.event.KeyEvent;
- import java.util.ArrayList;
- import javafx.animation.*;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.*;
- import javafx.scene.canvas.Canvas;
- import javafx.scene.canvas.GraphicsContext;
- import javafx.scene.control.Button;
- import javafx.scene.image.Image;
- import javafx.scene.input.KeyCode;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.paint.Color;
- import javafx.stage.*;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.shape.*;
- import javafx.util.Duration;
- /**
- * Main function extends Application from Application Library from JavaFX
- */
- public class Main extends Application {
- public static Stage stage;
- controller c = new controller();
- int x = 100, y = 100, aX = 400, aY = 400;
- int xSize = 600, ySize = 600, canvasX = 400, canvasY = 400;
- Canvas canvas = new Canvas(canvasX, canvasY); // Creates canvas which will contain things
- int time = 900;
- private boolean animationOn = false;
- Rectangle arena = c.createArena(x, y, aX, aY);
- Circle cir = c.createCircle(x+150, y+150);
- Circle cir2 = c.createCircle(x+80, y+150);
- private Timeline animation;
- private HBox setButtons() {
- // create button
- Button btnAnimOn = new Button("Start Animation");
- // now add handler
- btnAnimOn.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- animationOn = true;
- c.translate(cir, time);
- }
- });
- Button btnAnimOff = new Button("Stop Animation");
- btnAnimOff.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- animationOn = false;
- if (animationOn == false) {
- c.translate(cir, time);
- }
- }
- });
- return new HBox(btnAnimOn, btnAnimOff);
- }
- @Override
- public void start(Stage primaryStage) {
- stage = primaryStage;
- try {
- // Load the layout from the FXML and add it to the scene
- BorderPane bp = new BorderPane();
- bp.setBottom(setButtons());
- GraphicsContext gc = canvas.getGraphicsContext2D();
- bp.getChildren().addAll(cir, cir2, arena); // Adds all shapes and features.
- Scene scene = new Scene(bp, xSize, ySize);
- // Set the scene to stage and show the stage to the user
- primaryStage.setScene(scene);
- primaryStage.show();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment