Im trying to update the value my text_counter displays based on a change of the value. How do I achieve this? I've read somewhere on SO about binding it, but I have no clue what to bind it to. Anyone that can help me out?
public class main extends Application implements EventHandler<ActionEvent>{ Button button; Button button2; Counter counter = new Counter(0); Text text_counter = new Text(Integer.toString(counter.getCount())); public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Counter Window"); button = new Button(); button2 = new Button(); button.setText("Reset"); button.setOnAction(this); button2.setText("Tick"); button2.setOnAction(this); button.setTranslateY(-120); button2.setTranslateY(-120); button2.setTranslateX(50); text_counter.textProperty().bind(counter.getCount());
Counter?IntegerPropertyorLongProperty, for example). Then again, if that's all it does, you may as well use aSimpleIntegerPropertyetc. to begin with.