Приложение запускается, но при нажатии стрелки вверх ничего не происходит.
Код:
package sample;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.FlowPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import java.io.IOException;
public class Main extends Application {
private FlowPane pane;
private Scene scene;
private Stage stage;
@FXML
private Circle crc;
@Override
public void start(Stage stage) throws Exception{
this.stage = stage;
try {
pane = (FlowPane) FXMLLoader.load(Main.class.getResource("sample.fxml"));
} catch (IOException e){
e.printStackTrace();
}
stage.setTitle("Hello World");
scene = new Scene(pane,600,600);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
@FXML
public void initialize(){
crc.setOnKeyTyped(event -> {
if (event.getCode() == KeyCode.UP){
crc.setFill(Color.RED);
}
});
}
}
FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.shape.Circle?>
<FlowPane fx:controller="sample.Main" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.92" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Circle fx:id="crc" fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
</children>
</FlowPane>