2016-02-13 81 views
0

喜歡點擊按鈕,想爲我的屏幕負載做同樣的事情,我使用場景生成器。 這裏是我的代碼:JavaFx事件像Onload

public class CModifierBoutique implements ControlledScreen{ 
@FXML 
ChoiceBox<String> box;   

ScreensController myController; 
    @Override 
    public void setScreenParent(ScreensController screenPage) { 
     myController = screenPage; 
    } 
@FXML 
    private void goToMain(ActionEvent event){ 
     myController.setScreen(ScreensFramework.screen1ID); 
    }  
@FXML  
    private void inialize(ActionEvent event){ 
     System.out.println(" there is the method who must be start on load this screen "); 
     System.out.println("my code is requesting the data base and the result"); 
     System.out.println("will be added to my choisebox"); 

     BoutiqueDao dao=new BoutiqueDao(); 
     List<Boutique> li=dao.DisplayAll(); 


    } 
    } 

回答

1

我認爲你只是爲了尋找initialize()方法。無論你的控制器可以實現Initializable接口,並做

public class CModifierBoutique implements ControlledScreen, Initializable { 

    // existing code.. 

    @Override 
    public void initialize(URL location, ResourceBundle resources) { 
     // initialization code here... 
    } 
} 

,或者你可以只包含一個無參數的方法稱爲initialize()

public class CModifierBoutique implements ControlledScreen { 

    // existing code.. 

    public void initialize() { 
     // initialization code here... 
    } 
} 
+0

是的,但我想加載就在屏幕上「X」會被加載,因爲當我實現了初始化,它的工作原理當我的第一個屏幕將被加載 –

+0

是否有類似於javafx線程(GUI完成加載後)的初始化的替代方法。 ? – Mercury

+0

@Mercury不清楚你在問什麼。這正是initialize()所做的。 –