S
S
SoloCheater2018-08-09 17:41:53
Java
SoloCheater, 2018-08-09 17:41:53

How to call a variable (which is sealed in public void) after the code from the question description - JavaFX?

Hello. There is a code below. I need to call newValue variable from this code after this code. How to do it? If I call this variable after this code, then it writes an error newValue cannot be resolved to a variable.

// Adding Listener to value property.
    slider.valueProperty().addListener(new ChangeListener<Number>() {
  
       @Override
       public void changed(ObservableValue<? extends Number> observable, //
             Number oldValue, Number newValue) {
  
          infoLabel.setText("Вы выбрали: " + Math.round(newValue.floatValue()));
       }
    });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
EVGENY T., 2018-08-09
@SoloCheater

Declare a global variable at the beginning of the
Number globalValue class declaration;
and inside the changed function, fill it in:
globalValue = newValue;
Then use globalValue

D
Dmitry Alexandrov, 2018-08-09
@jamakasi666

Above you were answered with a crutch for which your hands are torn off. Get your value from slider.getValue()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question