1

Здраствуйте, столкнулся с проблемой, не могу вивести результат виполнения метода на десктопное окно так как setText() принимает только String, а метод void.

public static void createSession() throws Exception {

    session.getOnAuthenticationSuccessResponse().addObserver(authSuccessResponse ->{
            System.out.println("Auth success response received from authorization channel");

    });

    session.getOnAuthenticationFailedResponse().addObserver(authFailedResponse ->
            System.out.println("Auth failed response received from authorization channel - " + authFailedResponse.getFailedReason()));
  }

Ето сообщения которие я должен вивести на UI.

Ето мой контроллер

@FXML
private static TextArea Out;

public void Autentification(ActionEvent actionEvent) throws Exception {

    Connection.createSession();

    String name = "java_test002";// UserName.getText();
    String pass = "21918a";//Password.getText();
    String host = "m.islb.one";//Host.getText();

    String port = "30000";//Port.getText();
    int intPort = Integer.parseInt(port);


    Connection.session.tryConnect(name, pass, host, intPort);
 }

После нажатия кнопки юзер аутентифицируется и должны вивестись сообщения с метода выше.

1 ответ 1

0

Можно вывести сообщение на Label, если он есть в вашем UI:

   public class TestLabel extends Application {
        public static void main(String[] args) {
            Application.launch(args);
        }

        static Label outLbl ;

        @Override
        public void start(Stage stage) {


            outLbl = new Label("Out msg");

            VBox root = new VBox(outLbl);

            Scene scene = new Scene(root, 300,300);
            stage.setScene(scene);
            stage.show();
        }

        public static void createSession() throws Exception {

            session.getOnAuthenticationSuccessResponse().addObserver(authSuccessResponse ->{
                // вместо  System.out.println используем элемент UI 
                outLbl.setText("Auth success response received from authorization channel");

            });

            session.getOnAuthenticationFailedResponse().addObserver(authFailedResponse ->
            // вместо  System.out.println используем элемент UI 
            outLbl.setText("Auth failed response received from authorization channel - " + authFailedResponse.getFailedReason()));
          }
    }

В этом случае outLbl это глобальная переменная.

Есть другой вариант , если добавить в Ваш метод параметр Label:

public static void createSession(Label outLbl) throws Exception {

                session.getOnAuthenticationSuccessResponse().addObserver(authSuccessResponse ->{
                    // вместо  System.out.println используем элемент UI 
                    outLbl.setText("Auth success response received from authorization channel");

                });

                session.getOnAuthenticationFailedResponse().addObserver(authFailedResponse ->
                // вместо  System.out.println используем элемент UI 
                outLbl.setText("Auth failed response received from authorization channel - " + authFailedResponse.getFailedReason()));
              }
        }
0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.