N
N
Newmo2017-11-21 17:16:48
Java
Newmo, 2017-11-21 17:16:48

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("Здесь должен быть таймер");
            }
        }

Please tell me how to execute this code:
Controller.startonpause.setText("Здесь должен быть таймер");

Or maybe even a method in Controller.java from Main at once:
@FXML
    public void play() {
        mediaPlayer.play();
        Здесь изменить Label в FXML
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2017-11-21
@GavriKos

How to use a non-static method in a static class?

Call it through an instance of the class to which the method belongs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question