Skip to content
Snippets Groups Projects
App.java 1.19 KiB
Newer Older
Jan Kožusznik's avatar
Jan Kožusznik committed
package lab;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

/**
 *  Class <b>App</b> - extends class Application and it is an entry point of the program
 * @author     Java I
 */
public class App extends Application {

	public static void main(String[] args) {
		launch(args);
	}
	
	private Canvas canvas;
Jan Kožusznik's avatar
Jan Kožusznik committed
	private GameController controller;
Jan Kožusznik's avatar
Jan Kožusznik committed
	@Override
	public void start(Stage primaryStage) {
		try {
			//Construct a main window with a canvas.  
Jan Kožusznik's avatar
Jan Kožusznik committed
			
			
Jan Kožusznik's avatar
Jan Kožusznik committed
			Group root = new Group();
Jan Kožusznik's avatar
Jan Kožusznik committed
			canvas = new Canvas(800, 600);
Jan Kožusznik's avatar
Jan Kožusznik committed
			root.getChildren().add(canvas);
Jan Kožusznik's avatar
Jan Kožusznik committed
			Scene scene = new Scene(root);
			
			
Jan Kožusznik's avatar
Jan Kožusznik committed
			primaryStage.setScene(scene);
			primaryStage.resizableProperty().set(false);
Jan Kožusznik's avatar
Jan Kožusznik committed
			primaryStage.setTitle("Java 1 - 6th laboratory");
Jan Kožusznik's avatar
Jan Kožusznik committed
			primaryStage.show();
Jan Kožusznik's avatar
Jan Kožusznik committed
			controller = new GameController(canvas);
			controller.startGame();
Jan Kožusznik's avatar
Jan Kožusznik committed
			//Exit program when main window is closed
			primaryStage.setOnCloseRequest(this::exitProgram);
Jan Kožusznik's avatar
Jan Kožusznik committed
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
Jan Kožusznik's avatar
Jan Kožusznik committed

Jan Kožusznik's avatar
Jan Kožusznik committed
	
	private void exitProgram(WindowEvent evt) {
Jan Kožusznik's avatar
Jan Kožusznik committed
		controller.stopGame();
Jan Kožusznik's avatar
Jan Kožusznik committed
		System.exit(0);
	}
}