title: Adding text to a label from another class. Java
body: <p>In my program, there are two <code>Form</code> and <code>Checked</code> classes.</p>
  
  <p>In the <code>Form</code> class, there is a <code>Label</code> and a <code>Button</code>. At the click in the <code>Button</code> I create an instance of the class <code>Checked</code> and start its thread. </p>
  
  <p>Now, what I'm having trouble with is that I need to pass the text from the <code>Checked</code> class and change the <code>Label</code> value, but I have not succeeded.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class MainForm extends Application {
      protected static int intVerifiedNews = 0;
      Button btnPlay = new Button("Button");
      Label lbVerifiedNews = new Label("News: ");
      @Override
      public void start(Stage primaryStage) throws IOException {
  
          final BorderPane border = new BorderPane();
          final HBox hbox = addHBox();
  
          Scene scene = new Scene(border, 850, 500, Color.BLACK);
  
          btnPlay.setPrefSize(100, 24);
          btnPlay.setMinSize(24, 24);
  
          btnPlay.setOnAction((event) -&gt; {
                      Checked ch = new Checked();
                      ch.start();
                  }
          );
  
          border.setTop(hbox);
          hbox.getChildren().addAll(btnPlay, lbVerifiedNews);
          primaryStage.setScene(scene);
          primaryStage.show();
  
      }
      private HBox addHBox() {
          HBox hbox = new HBox();
          hbox.setPadding(new Insets(5, 0, 5, 5));
          return hbox;
      }
  
      public static void main(String[] args) throws IOException {
          launch(args);
      }
  }
  </code></pre>
  
  <p>Checked class:</p>
  
  <pre><code>public class Checked extends Thread {
  
  
      public void run() {
          for (int i = 0; i &lt;= 5; i++) {
      MainForm.intVerifiedNews ++;
  //Here you need to pass the intVerifiedNews value to the Label 
                  System.out.println(MainForm.intVerifiedNews);
          }
  
      }
  }
  </code></pre>