CSC 2040 Week 12 Multi-Scene & App Deployment PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document provides instructions and details for creating multi-scene JavaFX applications, setting up views, configuring builds, managing resources, and packaging applications using JAR files within NetBeans. The document also describes how to create and run a Maven FXML project and create a JAR file for this project.
Full Transcript
CSC 2040 Multi-Scene & App Deployment OBJECTIVES AGENDA: WEEK 12 Demonstrate how to create a 1. JavaFX Multi-Scene App multi-scene JavaFX Application Incorporate SceneBuilder 2. Application JAR Files application to setup View...
CSC 2040 Multi-Scene & App Deployment OBJECTIVES AGENDA: WEEK 12 Demonstrate how to create a 1. JavaFX Multi-Scene App multi-scene JavaFX Application Incorporate SceneBuilder 2. Application JAR Files application to setup View Demonstrate the process of 3. NetBeans IDE Packaging Tool configuring a JavaFX application 4. Step-By-Step Creating Self- build Contained Application Understand how to manage and package external resources 5. TODO Construct a self-contained JAR 6. Resources for Help file for a JavaFX application MULTI-SCENE APP: VIEWS 1. Using NetBeans create new fxml view files 2. Edit using SceneBuilder 3. Save files Secondary Initial Scene Scene Graph Graph MULTI-SCENE APP: VIEWCONTROLLERS 1. In NetBeans, make controllers for each view 2. Move controller file to source folder 3. Added a new resource folder named: images 4. Saved the resource image to this folder MULTI-SCENE APP: MAIN APP 1. In NetBeans, open the main file: App.java 2. Update the start method to load the initial scene graph on the scene 3. Take note of the shared private scene and shared public setRoot method that will be used to swap out the scene graphs MULTI-SCENE APP: SCENE GRAPH SWAP 1. Open the initial viewController and setup the event handler that will trigger the scene graph swap. 2. The initial viewController should have a static public method or field that can be accessed from the secondary viewController MULTI-SCENE APP: VIEWCONTROLLER 2 1. Open the secondary viewController and create a private field that will be set based upon the public static field or method from the initial viewController in the default constructor of the class APPLICATION PACKAGE: JAR FILE JavaFX applications can be packaged as a platform-specific, self-contained application JAR file. By default, all of the JavaFX packaging tools generate the packaged JAR file: A JAR file, contains the compiled class files and all application resources ie. images. The Java and JavaFX runtimes, and a launcher, They offer no-hassle compatibility. The version of Java Runtime used by the application is fully controlled by the application developer. The application is easily deployed on fresh systems with no requirement for Java Runtime to be installed. NETBEANS IDE PACKAGING TOOL NetBeans Maven FXML projects can be packaged using the tools within NetBeans. When you use the Clean and Build command of NetBeans, your application is packaged for JavaFX deployment, using options that are set as project properties. CREATING JAR FILE: STEP-BY-STEP 1. Create a Maven FXML project within NetBeans and have the program fully working within the Project Configuration: 2. Make sure all resources are saved within the project src/main/resources folder to be packaged into the final JAR file 3. Create a new Java Class named Main, that will execute the App.main The class App extends Application and for an executable package, the main class cannot extend any class besides Object. public class Main{ public static void main(String [] args){ App.main(args); } } CREATING JAR FILE: STEP-BY-STEP CONT. 4. Run the project to ensure the program runs 5. Copy the Maven Executable plugin to Project Files > pom.xml within … https://maven.apache.org/plugins/maven-shade- plugin/examples/executable-jar.html Note there will be multiple plugin elements within the plugins element Update the element to your specific package.Main, where Main is the new Java class that you created in step 3. edu.rrcc.logintohello.Main CREATING JAR FILE: STEP-BY-STEP CONT. 6. Change the Project Configuration to: release- profile 7. From the File menu select Project Properties Ensure the release- profile actions are setup as shown in the picture CREATING JAR FILE: STEP-BY-STEP CONT. 8. Clean and Build the project in NetBeans 9. Open the file explorer app for your operating system (ie. File Explorer on Windows or Finder on Mac) 10. Navigate within your NetBeans project to the target folder 11. You’ll see many JAR files, most likely it is the first JAR file. 12. Double-click the JAR file and the program runs as a self-contained application. Try out the project: LoginToHello-1.0-SNAPSHOT.jar EARN YOUR PRE-WORK GRADE Post your weekly discussion question and research solution to D2L TODO Complete Week 12 Content Module in D2L to 100% WHAT'S COMING UP NEXT...WEEK 13 QUESTIONS | CLARIFICATIONS | HELP Student Office Hours: Schedule Meeting with Julie Email: [email protected] RRCC On Campus Tutoring: https://www.rrcc.edu/learning- commons/tutoring 24/7 Online Tutoring: D2L > Content > Resources for Help