Day 22 Java FX - University of Texas at Austin

Day 22 Java FX - University of Texas at Austin

EE 422C Java FX What is JavaFX? Framework for developing GUI programs Replaced Java Swing Similar conceptually to other graphics libraries EE 422C

Why this JavaFX project? Learn how to use a large library without detailed instructions. Learn about event-driven software. Demonstrate the value of the MVC design pattern. Make a nice self-contained demo-able program to show off. EE 422C

How to run a JavaFX program Eclipse Command Line EE 422C Basic Structure The main class for a JavaFX application extends the

javafx.application.Application class. The start() method is the main entry point for all JavaFX applications (not main(), like in other Java applications). The launch(args) in main() does nothing usually. EE 422C EE 422C

EE 422C Stage, Scene, Node A JavaFX application defines the user interface container by means of a stage and a scene. The JavaFX Stage class is the top-level JavaFX container. Think of it as a stage on which a play is enacted. It is a window on our screen. The JavaFX Scene class is the container for all content. Think of it as a scene in a play.

Nodes are the actors to perform in the scene. EE 422C JavaFX Scene graph EE 422C Java FX Scene The Main class is an extension of the javafx.application.Application class. Its start

method is overridden and receives a Stage object (a top-level GUI container) as its only parameter. The root node (in this case, an instance of the javafx.scene.Stackpane class) is created and passed to the scene's constructor, along with the scene's width, and height. The stage's title, scene, and visibility are all set. EE 422C EE 422C

Coordinates The Origin is at the top left in JavaFX x (0, 0) y

Y Axis X Axis (x, y) Y Axis (0, 0)

Java Coordinate System Conventional Coordinate System X Axis

EE 422C Layout Panes JavaFX provides many types of panes for organizing nodes in a container. 13 Event-Driven Programming A paradigm where the flow of the program is

driven by events such as: User actions (buttons, mouse clicks, etc.) Sensor input Network traffic Messages from other programs or threads Very common in software with graphical user interfaces EE 422C

Event Handler event handler is a callback subroutine that handles inputs received in a program (called a listener in Java). Each event is a piece of application-level information from the underlying framework, typically the GUI toolkit. GUI events include key presses, mouse movement, action selections, and timers expiring. Event handlers are a central concept in event-driven programming.

EE 422C Event Handler EventHandler is a class that implements void handle(T event) Invoked when a specific event of the type for which this handler is registered happens. btn.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) {

newScreen(stage); //action for button } }); //We will look at a more concise version later EE 422C Java FX program snippet class Main extends Application {} Add method start(Stage primaryStage) that works like main (String[] args) to Main

Add a Scene to the primaryStage in start() Add a JavaFX Node object (such as a grid) to the Scene Add button to the Node object Add onAction code (event Handler) to the button Display the primaryStage on the computer display EE 422C

Recently Viewed Presentations

  • Ancient Achievements:

    Ancient Achievements:

    What should I know about ancient achievements?. The priorities and cultural values of a civilization are reflected in their artistic and scientific achievements. People TRANSFORM their culture through achievements that help them meet their needs and wants.
  • GCSE Film Studies

    GCSE Film Studies

    There is often a real baddie and this could be the bureaucrat and often they meet a particular sticky end that we can enjoy - certainly - unlike in real life - the person who is to blame or the...
  • MedlinePlus, MedlinePlus Connect and the NLM Web Site

    MedlinePlus, MedlinePlus Connect and the NLM Web Site

    MedlinePlus, MedlinePlus Connect & the NLM Web Site. Loren Frant. [email protected]
  • TNS Template Feb 2009 - Cloudinary

    TNS Template Feb 2009 - Cloudinary

    By group, Houston residents' satisfaction drops from last year (67% from 82%), but still exceeds the level noted by other Texans (53%). Satisfied visitors help build strong word-of-mouth "advertising" that every destination needs to supplement their advertising campaigns. The Website,...
  • Childhood Obesity - Jackson School District

    Childhood Obesity - Jackson School District

    "No nation is healthier than its children" Harry S. Truman. 1946. Facts about childhood obesity. Childhood obesity has doubled in children and tripled in adolescents in the last 30 years. More than one-third of children and adolescents were considered overweight...
  • REGISTRATION - Springtown ISD

    REGISTRATION - Springtown ISD

    Alternates are very important!!! If we do have an 8 period day, your first alternate will be used to fill that 8th slot. If we have 7 periods but you can't get one of the electives you'd like, this is...
  • Tutorials on Data Management CC Image courtesy of

    Tutorials on Data Management CC Image courtesy of

    The Data Life Cycle. Assure. Preserve. Discover. Integrate. Analyze. Plan. Describe. Collect. In this lesson we will be focusing on data protection and backup which is associated with the categories assure and preserve in the data life cycle.
  • Overview of Workshop - Purdue University

    Overview of Workshop - Purdue University

    Purdue Space Day. Projects: Education. Columbian Park Zoo. Electric Vehicle. Design cart for race. Outreach. Purdue EPICS Course Structure. ... 3 credits senior design + 6 ECE elective credits; 2 lab credits if not used as senior design. CmpE: 3...