Answer the question
In order to leave comments, you need to log in
How to use a non-static method in a static class?
I am writing a simple player, an audio recording is played by the f2 button. I had to use the jNativeHook library to capture the pedal so that the user could type outside the active window. Faced a problem:
I can not change the Label when you press the pedal. (java: non-static method play() cannot be referenced from a static context)
I am not very familiar with Java, but in general, the program is almost finished, so I got stuck on such a trifle. In this Label, I want to display the time from which the user continued playback.
I track the pressed pedal in Main:
public static class GlobalKeyListenerExample implements NativeKeyListener {
//Если кнопка нажата
public void nativeKeyPressed(NativeKeyEvent e) {
GlobalScreen.unregisterNativeHook();
//Проверяем нажатие кнопки f2
if (e.getKeyCode() == NativeKeyEvent.VC_F2) {
//System.out.println("Зажата");
Controller.mediaPlayer.play();
Controller.startonpause.setText("Здесь должен быть таймер");
}
}
Controller.startonpause.setText("Здесь должен быть таймер");
@FXML
public void play() {
mediaPlayer.play();
Здесь изменить Label в FXML
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question