Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.23 KB | None | 0 0
  1. package start;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import javafx.application.Application;
  6. import javafx.event.Event;
  7. import javafx.event.EventHandler;
  8. import javafx.scene.Scene;
  9. import javafx.scene.image.Image;
  10. import javafx.scene.image.ImageView;
  11. import javafx.scene.layout.BorderPane;
  12. import javafx.stage.Stage;
  13. import utilities.Config;
  14. import window.Fenetre;
  15. /**
  16.  * @author Alexandre Vettese, Martin Dierckxsens, Michael Genique
  17.  */
  18. public class Main extends Application {
  19.     private Fenetre fenetre;
  20.     private BorderPane borderMain;
  21.     private ImageView imgStart;
  22.     private Scene windowStart;
  23.     private static Config config;
  24.     /**
  25.      * IF we haven't any fenetre, this method create ones and give the result.
  26.      * @return a fenetre from the class fenetre.
  27.      */
  28.     public Fenetre getFenetre() {
  29.         if(fenetre==null) {
  30.             fenetre=new Fenetre();
  31.         }
  32.         return fenetre;
  33.     }
  34.     /**
  35.      * If the data boerderMain is null, we create it and we put an image in the center.
  36.      * @return a border pane.
  37.      */
  38.     public BorderPane getBorderMain() {
  39.         if (borderMain == null) {
  40.             borderMain = new BorderPane();
  41.             borderMain.setCenter(getImageStart());
  42.         }
  43.         return borderMain;
  44.     }
  45.     /**
  46.      * 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.
  47.      * @return a scene.
  48.      */
  49.     public Scene getScene() {
  50.         if (windowStart == null) {
  51.             windowStart = new Scene(getBorderMain(), config.getWidth(), config.getHeight());
  52.         }
  53.         return windowStart;
  54.     }
  55.     /**
  56.      * 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.
  57.      * When the image is clicked, the window vanished and we see the second one.
  58.      * @return an image that appears in the first window.
  59.      */
  60.     public ImageView getImageStart() {
  61.         if (imgStart == null) {
  62.             Image image = null;
  63.             try {
  64.                 image = new Image(new FileInputStream("./image/TrivialStart.jpg"));
  65.             } catch (FileNotFoundException e) {
  66.                 e.printStackTrace();
  67.             }
  68.             imgStart = new ImageView();
  69.             imgStart.setFitHeight(config.getHeight());
  70.             imgStart.setFitWidth(config.getWidth());
  71.             imgStart.setImage(image);
  72.             imgStart.setOnMouseClicked(new EventHandler<Event>() {
  73.  
  74.                 @Override
  75.                 public void handle(Event arg0) {
  76.                     borderMain.getChildren().remove(0);
  77.                     borderMain.setCenter(getFenetre());
  78.                     System.out.println("clicked on picture");
  79.                 }
  80.             });
  81.         }
  82.         return imgStart;
  83.     }
  84.     /**
  85.      * @return the height of the screen.
  86.      */
  87.     public double getHeightScene() {
  88.         return windowStart.getHeight();
  89.     }
  90.     /**
  91.      * @return the width of the screen.
  92.      */
  93.     public double getWidthScene() {
  94.         return windowStart.getWidth();
  95.     }
  96.  
  97.     public static void main(String[] args) {
  98.         config = new Config();
  99.        
  100.         launch(args);
  101.     }
  102.     /**
  103.      * @throws Exception
  104.      * We use a try/catch.
  105.      * The title is set, we get the scene and we show them in full screen.
  106.      */
  107.     public void start(Stage arg0) throws Exception {
  108.         try {
  109.             arg0.setTitle("Trivial Purr'suit");
  110.             arg0.setScene(getScene());
  111.             arg0.show();
  112.             arg0.setFullScreen(true);
  113.         } catch (Exception e) {
  114.             e.printStackTrace();
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement