我如何从另一个类调用fxml private anchorpane

时间:2015-04-19 00:27:08

标签: javafx controller javafx-8 fxml

我想从另一个类调用anchorpane并为其添加画布。什么是我的问题最简单的解决方案。

我是Javafx的新手

TlmeLineFxController.java

    public class TlmeLineFxController implements Initializable {

        @FXML
        private AnchorPane myViewAPid;
// more code
    .....
    }

AddEventFxController.java

    public class AddEventFxController implements Initializable{
        //more code

   @FXML
  void saveEvent(ActionEvent event) {
        // i get an error here because i need to put static to @FXML private AnchorPane myViewAPid;
        TlmeLineFxController.myViewAPid.getChildren().add(CanvasNewTimeLine.drawEventDuration());

        }
//more code
    }

CanvasNewTimeLine.java

public class CanvasNewTimeLine {    

    public static Canvas drawEventDuration(){

            Canvas canvas = new Canvas((yearsNO*120)+100, 200);
            GraphicsContext gc = canvas.getGraphicsContext2D();
            drawShapesEventDuration(gc);


            return canvas;

        }


        private static void drawShapesEventDuration(GraphicsContext gc) {

            //      TimeLine length  |-------------|
            gc.fillText(TLtitle, 40, 40);
    // more code....
      }
    }

0 个答案:

没有答案