JAVA 14: DEVELOPMENT OF APPLICATIONS WITH JAVAFX by POUL KLAUSEN
Author:POUL KLAUSEN [KLAUSEN, POUL]
Language: eng
Format: azw3
Publisher: UNKNOWN
Published: 2021-01-14T16:00:00+00:00
WITH JAVAFX: SOFTWARE DEVELOPMENT
WITH JAVAFX: SOFTWARE DEVELOPMENT COMPONENTS private Label createLabel() {
Label label = new Label("Enter to start"); label.setLayoutX(20);
label.setLayoutY(20);
return label;
}
public static void main(String[] args) {
launch(args);
}
}
The class defines a variable for a transition, which is the animation that rotates the square. It is created by the method createRotate(), which does not contain anything new in terms of animations. The actual Transition object is created in the method start(). Here you should also notice how to set the background color for the window. The square is created in the method createRect(). Here, the method setOnMouseClicked() is used to attach an event handler for mouse clicks to the square, and you should note how the event handler is defined using a lambda expression.
Then there is the method createField() that creates the entry field. It is a TextField, and the most important is the association of the event handler. It is a filter and the handler is associated for a KeyEvent of the type KEY_TYPED. The handler uses the method getCharacter() to test what has been entered and has the first character the code 13, it is the Enter key that is pressed, and if so, the animation will start. For any event, the event is marked as cosumed so that it is not passed on in the chain, and the effect is that the character for the key pressed is never displayed in the input field.
The example thus shows how to catch events for mouse and keyboard. In the example, it happens in two different ways, where in createField() it takes place at low level with addEventFilter() while in createRect() it occurs using a convenience method. Many of the JavaFX classes defines event handlers as properties, and you can then register an event handler using a set method for that convenience method. The goal is to make it easier to associate event handlers what the following program HandlerProgram should illustrate:
WITH JAVAFX: SOFTWARE DEVELOPMENT componentS
Clicking the Start button starts an animation where the circle moves along the curve and the animation runs until you click the stop button. If you click on the circle, it changes color.
.
WITH JAVAFX: SOFTWARE DEVELOPMENT
WITH JAVAFX: SOFTWARE DEVELOPMENT COMPONENTS public class HandlerProgram extends Application {
private boolean blue = true; private Transition trans;
@Override
public void start(Stage stage) {
Circle circle = createCircle();
Path path = createPath();
trans = createTrans(circle, path);
Group root = new Group(createButton("Start", 20, e -> trans.play()),
createButton("Stop", 120, e -> trans.stop()), path, circle); Scene scene = new Scene(root, 560, 400);
scene.setFill(Color.BEIGE);
stage.setTitle("Move");
stage.setScene(scene);
stage.show();
}
private Button createButton(String text, int pos, EventHandler<ActionEvent> handler)
{
Button cmd = new Button(text);
cmd.setLayoutX(pos);
cmd.setLayoutY(20);
cmd.setPrefSize(80, 25);
cmd.setOnAction(handler);
return cmd;
}
private Transition createTrans(Shape shape, Path path) {
PathTransition trans = new PathTransition();
trans.setDuration(Duration.millis(3000));
trans.setNode(shape);
trans.setPath(path);
trans.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT); trans.setCycleCount(50);
trans.setAutoReverse(true);
return trans;
}
private Circle createCircle() { Circle circle = new Circle(40, 80, 25, Color.BLUE); circle.setStrokeWidth(20);
circle.setOnMouseClicked(
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9913)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9795)
The Mikado Method by Ola Ellnestam Daniel Brolund(9777)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8295)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7778)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Windows APT Warfare by Sheng-Hao Ma(6819)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6549)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6416)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Kotlin in Action by Dmitry Jemerov(5062)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4316)
Functional Programming in JavaScript by Mantyla Dan(4037)
Solidity Programming Essentials by Ritesh Modi(3993)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3784)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3724)
The Ultimate iOS Interview Playbook by Avi Tsadok(3700)
