Main.java
Код: Выделить всё
package application;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
public class Main extends Application {
public final Counter counter = new Counter();
public final SimpleStringProperty labelText = new SimpleStringProperty();
public Label countLabel = new Label("default text");
public void initialize() {
labelText.addListener((observable, oldValue, newValue) -> {
System.out.println("Changed: " + oldValue + " -> " + newValue);
});
countLabel.textProperty().set("test");
counter.getProperty().addListener((observable, oldValue, newValue) -> {
labelText.set("Click! " + newValue + " total clicks!");
});
countLabel.textProperty().bind(labelText);
}
@Override
public void start(Stage primaryStage) {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("views/Main.fxml"));
StackPane root = loader.load();
root.getChildren().add(countLabel);
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Подробнее здесь: https://stackoverflow.com/questions/789 ... -duplicate