Friday, December 9, 2016

JavaFX : Basic Framework

Every JavaFX program must adhere to its minimum requirement. At the very basic it comprises of :
  • the library of javafx.application.Application and javafx.stage.Stage
  • It is a class extends or inherits from Application
  • Inside the class there is method overriding : start()
  • An object of stage


  • Remember those 4 requirements in order to be able to run a JavaFX apllication. The very first program is written below :

    package javafxfirstapplication;

    import javafx.application.Application;
    import javafx.stage.Stage;

    /**
     *
     * @author Joko Adianto
     */
    public class JavaFXFirstApplication extends Application {
        
        @Override
        public void start(Stage primaryStage) {
            primaryStage.setTitle("JavaFX : First Application");        
            primaryStage.show();
        }

        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            launch(args);
        }
        
    }

    The picture below is the screenshot of the above program




    Here are four exercises to write a JavaFX program that has title of

    JavaFX : Second application
    ....
    ....
    @Override
        public void start(Stage primaryStage) {
            primaryStage.setTitle("JavaFX : Second Application");        
            primaryStage.show();
        }
    ....
    ....

    JavaFX : Third application
    ....
    ....
    @Override
        public void start(Stage primaryStage) {
            primaryStage.setTitle("JavaFX : Third Application");        
            primaryStage.show();
        }
    ....
    ....

    JavaFX : Fourth application
    ....
    ....
    @Override
        public void start(Stage primaryStage) {
            primaryStage.setTitle("JavaFX : Fourth Application");        
            primaryStage.show();
        }
    ....
    ....

    JavaFX : Fifth application
    ....
    ....
    @Override
        public void start(Stage primaryStage) {
            primaryStage.setTitle("JavaFX : Fifth Application");        
            primaryStage.show();
        }
    ....
    ....

    I think its better to rewrite those program, than just "Copy & Paste"ing. 





    No comments:

    Post a Comment