如何在java fx中更改连续线程中的值?

时间:2017-05-19 19:03:26

标签: java multithreading javafx

使用以下代码,在控制器类中单击按钮时激活该线程。事实是,我希望能够更改Line数组中的值,必须锚定窗格擦除旧行并添加新行。这是在main.in the launch之后的controller.java中。

static startVal = -1,endVal = -1;
Lines L;//this is supposed to store new lines after some methods are called


//this method is called on button click and I want it to start again every time the button is clicked
public void drawPath(){
        Task task = new Task<Void>() {
      @Override
      public Void call() throws Exception {
       while(true){
            int i = 0;
            while (i<5) {
                final int finalI = i;
                Platform.runLater(new Runnable() {
                  @Override
                   public void run() {
                   anchPane.getChildren().add(L[finalI]);

                  if(startVal == -1)
                       startVal = anchPane.getChildren.size()-1;
                   else
                      endVal = anchPane.getChildren().size()-1;
                }
              });
              i++;
              Thread.sleep(2000);
            }

          //removeLines();
          anchPane.getChildren().remove(startVal,endVal);
              }

          }
        };
        Thread th = new Thread(task);
        th.setDaemon(true);
        th.start();          
    }

0 个答案:

没有答案