Description
The next several activities will take you through the features of JavaFX, where you will learn how to display graphics, build Graphical User Interfaces (GUIs), use the animation capabilities of JavaFX to create dynamic web applications. All of these skills will be applied when you build your media player.
This activity introduces you to the syntax of the JavaFX scripting language. Syntax is the vocabulary (the words) of the language, and the rules for putting them together. In a spoken language, in order to be understood you need to use words from the vocabularly, and you need to follow the rules of grammer when you put together sentences, in order to be understood; if you use English vocabulary in France, or string your words together in random order, you may not get the result you desire! The same is true when talking to a computer. Fortunately, computer languages usually have a pretty small vocabularly, the grammar rules are simple, and you have NetBeans to help you communicate effectively (and tell you when you are doing it wrong).
In this activity, you will:
- create a small JavaFX appliaction that displays a circle and a square on the screen
Skills you will learn include:
- understanding JavaFX import statements, which import the classes you will use into your application code
- learn how to declare node objects, such as Circle and Rectangle, within the content variable of a Scene
Basic Steps
Now we're going to create our second JavaFX program, and in the process, get familiar with some of the important components JavaFX syntax.
- Open NetBeans, and create a new project. Under the File menu, select New Project, and go through the new project wizard, creating a JavaFX project. Remember, if you need help, use the forum!
- When your have completed the wizard, you will see the project in your NetBeans Project list. To make life easier, we will set this new project as the Main Project. This allows you to easily build and run your project using the Build Main Project and Run Main Project controls in NetBeans. To set your new project as the Main Project, you can look under the Run menu, there is a Set Main Project menu item; use that to select your new project as the main project. Alternatively, you can "right-click" on your project's name, and there should be a "Set as Main Project" item in the context menu.
- Now go to Lesson 2: Using Declarative Syntax in the JavaFX GUI Applcation tutorial. Go through the tasks of this lesson. You will be introduced to the concepts of the Stage and the Scene, which are important parts of the JavaFX syntax (the vocabulary of the scripting language). It's pretty simple: the Stage holds the Scene, and the Scene holds the Nodes. The Nodes are the things that actually display on the screen. You can copy the code from the lesson into your NetBeans project, build it, and run it. One thing I want to point out, there are a couple of places in the lesson where you will see elipses (...) in the code listing. You do NOT type the elipsis into your code! This is just an indication that there was some code that you typed in earlier, and this new code listing will not repeat that earlier code; instead, they use elipses to show that there should be some code here, but they already showed it earlier, and don't want to clutter up the lesson by repeating it. I think you'll understand it when you see it, but I just want to avoid that issue, I don't want you getting stuck with what might be a silly error, typing the ... into your code.
- Submit your project that you created to the activity. You will submit a jar file (a java archive file) that contains your runable program. To find the jar file, open your project in NetBeans, and note that in the project pane, there are 3 tabs: Projects, Files, Services. Select the Files tab. Expand your project folder by clicking on the '+' sign. You should see a folder called 'dist'. Expand the dist folder, you will probably see a few files and maybe some folders. One of the filenames should end in .jar. This is the file that you will submit. Open the context menu on that file (on Windows, right-click on the file; on Mac, Ctrl-click on it), and select 'properties' from the menu. One of the properties will be the full path to where the jar file lives on your system. Use your file browser to go get the file, and submit it.


Want to learn how to create animated content for your website?