Quick Contact

    Hibernate

    JavaFXGradle

    In Java, JavaFX helps in creating desktop applications as well as games. Gradle is considered as one of the top build systems present on the Java platform. Nowadays, plethora of projects is migrated to gradle from maven and ant etc. Using this plugin boosts the build-script and moreover, gradle-plugin wraps every call as well as introduces workarounds along with fixes for JDK-bugs.

    How does JavaFXGradle Plugin Work?

    In order to work with gradle, we have to setup the same. For that, some steps has to be performed.

    Step 1:

    Download JDK8 and install it for the platform you use. Always remember to download the JDK based on your platform. Then, verify the same by using the command java – version and running it.

    Before moving to next step, you have to know what JDK is.

    Note:

    JDK is the Java Development Kit that is considered as Java programming language’s one of the top 3 primary technology packages. Other two are JVM (Java Virtual Machine) which is the component that executes programs in Java and JRE (Java Runtime Environment) which is the Java’s on-disk part that helps in creating the Java Virtual Machine.

    Step 2:

    After installing JDK, download Eclipse IDE and install the same.

    For that, extract the downloaded zip and double click on the exe (executable file) for verifying whether the downloaded eclipse is up and running.

    Note:

    Eclipse is an IDE that helps in programming which consists of a base workspace along with a wide plug-in system. This is mainly for environment customization.

    Step 3:

    Normally, Eclipse has in-built gradle support (that is, buildshipgradle plugin). But, the default version can be old sometimes. For that, the gradlebuildship has to be updated.

    For that, perform the steps below.

    • Open Eclipse.
    • Click on the menu Help.
    • Choose Eclipse Marketplace.
    • Find the buildship with the help of field find on the top.
    • Click go.
    • Click on the button installed/install for updating the buildship. On clicking it, the page will take the user to the tab installed.
    • Click on the button update. On clicking this, the update starts and buildship gets updated.
    • Once these steps are done, restart eclipse.
    • If you want to check whether the buildship is installed or not, perform the below steps.

    • Open Eclipse.
    • Click on the menu Help.
    • Choose Eclipse Marketplace.
    • Click on the button installed/install for viewing the installed buildship.

    Normally, you will be able to see the buildship in that section. If it is not visible, close the eclipse and start again.

    Note:

    Gradle is considered as a build automation tool that helps in multi-language software development which controls the task compilation and packaging to testing development process along with deployment, as well as publishing. C/C++ and JavaScript are the other programming languages that support gradle.

    Step 4:

    Next, a JavaFX project has to be created with the help of gradle.

    Now, we will see how to do that. For that, following steps has to be performed.

    • Open Eclipse.
    • Click on the menu File.
    • Choose.
    • Select Other.
    • Select the GradleProject from the Gradle option.
    • Give a name for the project you have created.
    • Click Next.
    • Then click Finish.

    As this is the first gradle project you have created, it will download libraries for the project.

    Step 5:

    Once all these steps are done, create a simple Java class and save it within the project folder src/main/java.

    Note:

    Normally, when you create a new class, it will be automatically saved into the location src/main/java.

    Example of JavaFXGradle

    Let us see a sample program which is created on the gradle project.

    JavaFX program that works on a gradle project.

    Code:

    //JavaFX program that works on a gradle project and displays a button with text

    //import all the necessary packages
    import javafx.application.Application ;
    import javafx.scene.Scene ;
    import javafx.scene.control.Button ;
    import javafx.scene.layout.StackPane ;
    import javafx.stage.Stage ;
    // main class
    public class JavaFXDemoSample extends Application
    {
    //main method
    public static void main(String[] args)
    {
    //application starts here
    launch(args);
    }
    // entry point of the program
    @Override
    // st is the window at top level which is created by the platform
    public void start(Stage st) throws Exception
    {
    //declare a msg
    String msg = "Hey !!! It is working !!!" ;
    //create a button
    Button btn1 = new Button();
    //set a text for the button
    btn1.setText(msg);
    // For UI controls, create a layout container
    StackPanesp = new StackPane();
    //add children
    sp.getChildren().add(btn1);
    // a container at top level for viewing all content
    Scene sc = new Scene( sp , 350 , 300 );
    //set title for the stage
    st.setTitle(msg);
    //set the scene
    st.setScene(sc);
    //display the result
    st.show();   } }
    

    Apply now for Advanced Java Training Course

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.