Java
/
JavaFX
- 1 Basics 9
-
Classes
-
Objects
-
Arrays
-
Variables
-
Loops
-
Numbers
-
Strings
-
Exceptions
-
Regexp
- 2 OOP 9
-
Inheritance
-
Polymorphism
-
Static
-
Abstract
-
Interfaces
-
Constructors
-
Packages
-
Nested Classes
-
Final
- 3 Compiler 2
-
Sublime Text
-
Apache Ant
- 4 Collections 8
-
Lists
-
Comparable
-
Sets
-
Maps
-
Generics
-
Properties
-
Streams
-
Json
- 5 Threads 4
-
Create Thread
-
Sleep
-
Lock
-
Scheduler
- 6 Design patterns 4
-
Singleton
-
Observer
-
Strategy
-
Mediator
- 7 Swing 12
-
Frame
-
Panel
-
Listener
-
Combo Box
-
Label
-
Image
-
Menu
-
Table
-
Layout
-
Drawing
-
Timer
-
Designer
- 8 I/O 7
-
Streams IO
-
Socket
-
Watching Files
-
Mail
-
Logger
-
Clipboard
-
Encrypt
- 9 Effective 7
-
Constructors
-
Dependency Injection
-
Composition
-
Interfaces Default
-
Import Static
-
Enums
-
Lambdas
- 10 Junit 5
-
About Junit
-
Test Case
-
Suite Test
-
Annotations
-
Exceptions
- 11 Lambdas 7
-
Expressions
-
Functional Interfaces
-
Streams
-
Common Operations
-
Default Methods
-
Static Methods
-
Single Responsibility
- 12 JavaFX 6
-
Openjfx
-
Scene Builder
-
First App
-
Jar Archive
-
On Action
-
Change Listener
- 13 Maven 4
-
Demo
-
Spring Boot
-
Junit
-
Guava
- 14 Spring Boot 8
-
Quick start
-
Rest service
-
Consuming Rest
-
Templates
-
Security
-
Command Line
-
Scheduling Tasks
-
Ajax
/
On Action
➟
➟
Last update: 17-11-2021
On Action
p 338 Add ActionApp main class with button action listener method.
/**
* FXML on action method is defined in ...
* Scene Builer 'on Action'
*/
package com.minte9.javafx.on_action;
import javafx.fxml.FXML;
public class ActionApp {
public static void main(String[] args) {
ActionAppGui.main(args);
}
@FXML void buttonPressed() { // Look Here
System.out.println("button pressed");
}
}
Launch
Add ActionAppGui class that loads fxml file.
/**
* Gui class with button.xml loader
*/
package com.minte9.javafx.on_action;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class ActionAppGui extends Application {
public static void main(String[] args) {
launch(args);
}
@Override public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("button.fxml"));
stage.setTitle("Button Event FXML");
stage.setScene(new Scene(root));
stage.show();
}
}
Scene Builder
Set controller and button method (buttonPressed).
Containers / Add VBox
Controllers / Add Button
Controller / ControllerClass ... com.minte9.javafx.on_action.ActionApp
Button / Inspector / Code / On Action ... buttonPressed
Preview / Show Preview in Window
View / Show sample Controller Skeleton
Save ... button.fxml
Instance
Each value for a JavaFX object is used to set object's instance variables.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity"
prefHeight="400.0" prefWidth="600.0"
xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.minte9.javafx.on_action.ActionApp">
<children>
<Button mnemonicParsing="false" onAction="#buttonPressed" text="Button" />
</children>
</VBox>
➥ Questions github JavaFX