Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package start;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import javafx.application.Application;
- import javafx.event.Event;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import javafx.scene.layout.BorderPane;
- import javafx.stage.Stage;
- import utilities.Config;
- import window.Fenetre;
- /**
- * @author Alexandre Vettese, Martin Dierckxsens, Michael Genique
- */
- public class Main extends Application {
- private Fenetre fenetre;
- private BorderPane borderMain;
- private ImageView imgStart;
- private Scene windowStart;
- private static Config config;
- /**
- * IF we haven't any fenetre, this method create ones and give the result.
- * @return a fenetre from the class fenetre.
- */
- public Fenetre getFenetre() {
- if(fenetre==null) {
- fenetre=new Fenetre();
- }
- return fenetre;
- }
- /**
- * If the data boerderMain is null, we create it and we put an image in the center.
- * @return a border pane.
- */
- public BorderPane getBorderMain() {
- if (borderMain == null) {
- borderMain = new BorderPane();
- borderMain.setCenter(getImageStart());
- }
- return borderMain;
- }
- /**
- * If windowStart is null, we create it and we take the data borderMain, also the width and the height tanks to the method in the class Config.
- * @return a scene.
- */
- public Scene getScene() {
- if (windowStart == null) {
- windowStart = new Scene(getBorderMain(), config.getWidth(), config.getHeight());
- }
- return windowStart;
- }
- /**
- * If imgStart is null, we create it. With a try catch the program search the image in the file and take them. In the catch we have the exception if the file is not found.
- * When the image is clicked, the window vanished and we see the second one.
- * @return an image that appears in the first window.
- */
- public ImageView getImageStart() {
- if (imgStart == null) {
- Image image = null;
- try {
- image = new Image(new FileInputStream("./image/TrivialStart.jpg"));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- imgStart = new ImageView();
- imgStart.setFitHeight(config.getHeight());
- imgStart.setFitWidth(config.getWidth());
- imgStart.setImage(image);
- imgStart.setOnMouseClicked(new EventHandler<Event>() {
- @Override
- public void handle(Event arg0) {
- borderMain.getChildren().remove(0);
- borderMain.setCenter(getFenetre());
- System.out.println("clicked on picture");
- }
- });
- }
- return imgStart;
- }
- /**
- * @return the height of the screen.
- */
- public double getHeightScene() {
- return windowStart.getHeight();
- }
- /**
- * @return the width of the screen.
- */
- public double getWidthScene() {
- return windowStart.getWidth();
- }
- public static void main(String[] args) {
- config = new Config();
- launch(args);
- }
- /**
- * @throws Exception
- * We use a try/catch.
- * The title is set, we get the scene and we show them in full screen.
- */
- public void start(Stage arg0) throws Exception {
- try {
- arg0.setTitle("Trivial Purr'suit");
- arg0.setScene(getScene());
- arg0.show();
- arg0.setFullScreen(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement