2016-01-29 62 views
0

我折磨谷歌與多個問題,但仍不能得到一個觀點。JAVAFX場景生成器多個控制器

我想建立的應用程序與SceneBuilder填充2個FXML場景。每個都有自己的控制器。 我使用ControlledScreen交換場景,這個工程。 但是,我不能改變場景中的任何東西。 例如:我有標籤的場景控制器:

public class ControllerForm implements ControlledScreen, Initializable { 

    ScreensController myController; 
     GraphicsContext GC; 

     @FXML 
      private Label fitnessLabel; 

public void updateFitnessLabel(double data) { 
       fitnessLabel.setText(String.valueOf(data)); 
      } 

public void initialize(URL location, ResourceBundle resources) { 
      this.GC = neuroCanvas.getGraphicsContext2D(); 
       } 

它在FXML文件中定義爲:

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="684.0" prefWidth="918.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="general.ControllerForm"> 
    <left> 
     <VBox prefHeight="400.0" prefWidth="189.0" BorderPane.alignment="CENTER"> 
     <children> 
    <Label fx:id="fitnessLabel" text="Label"> 
        <graphic> 
         <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Fitness:" /> 
        </graphic> 
       </Label> 

和功能更新標籤updateFitnessLabel。

在初始化方法我用GC因爲我對這個場景帆布和要畫就可以了。

我有方法正在調用該溫控功能爲:

public class Net { 
private ControllerForm controller; 

    public void drawStart() throws IOException { 
    FXMLLoader loader = new FXMLLoader(
         getClass().getResource(
           Main.ScreenFile 
         ) 
       ); 

       BorderPane cv = loader.load(); 
       // load actual screen 
       ControllerForm controller = 
         loader.<ControllerForm>getController(); 

       controller.updateFitnessLabel(12);} 

但沒有效果。標籤不會被更新。

我失去了什麼?

我試圖用時間軸,但仍然沒有效果。 如何執行在這個場景上繪製的東西?

+1

如果您可以提供更多的上下文,這將有所幫助。 FXML是什麼樣的?有沒有其他相關的控制器代碼? –

+0

沒有更多的相關。 FXML是標準的。如果我在初始化時繪製一些東西,那麼控制器就會出現。 – SystemFailure

+0

沒有FXML和其他代碼示例,將很難幫助診斷您的問題。 –

回答

相關問題