JavaFX用FXML打开新场景

时间:2014-10-27 15:42:26

标签: java javafx fxml scene

所以我现在已经尝试了至少4个小时并没有成功。

案例:按下Controller类上的按钮后,我需要打开一个新的FXML窗口。 我正在使用JavaFX。 我们正在使用这样的软件包。

lobby.gui,login.gui等......

它没有给出错误信息,但场景不会启动。

这是按下按钮的LoginFXController。

public class LoginFXController implements Initializable
{
DatabaseMediator mediator;

//INLOGGUI FXML
@FXML TextField tf_inlogusername;
@FXML PasswordField pf_inlogpassword;
@FXML Button btn_inlog;
@FXML Button btn_register;

@Override
public void initialize(URL url, ResourceBundle rb) 
{
     mediator = new DatabaseMediator();
} 

public void loginPersoon(Event event)
{
    String gebruikersnaam = tf_inlogusername.getText();
    String wachtwoord = pf_inlogpassword.getText();
    Persoon p = new Persoon(gebruikersnaam, wachtwoord);
    Boolean check = mediator.controleerPersoonsGegevens(gebruikersnaam, wachtwoord);

    if(check == false)
    {
        showDialog("Error", "Gegevens komen al voor in het Systeem!");
    }
    else
    {      
        showDialog("Succes", "Welkom: " + gebruikersnaam);

        try
        {
            FXMLLoader loader = new   FXMLLoader(getClass().getResource("lobby.gui/LobbyGUI.fxml"));
            LobbyGUI controller = new LobbyGUI();
            loader.setController(controller);
            loader.setRoot(controller);
            Parent root = (Parent)loader.load();

            Stage stage = new Stage();
            stage.setScene(new Scene(root));
            stage.show();
        }
        catch(IOException e)
        {
             showDialog("Error", e.getMessage());
        }
    }  
}   

我试图解雇这个新班级

public class LobbyGUI extends Application
{
@Override
public void start(Stage stage) throws IOException
{
    Parent root = FXMLLoader.load(getClass().getResource("LobbyGUI.fxml"));

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
}  

/**
 * The main() method is ignored in correctly deployed JavaFX application.
 * main() serves only as fallback in case the application can not be
 * launched through deployment artifacts, e.g., in IDEs with limited FX
 * support. NetBeans ignores main().
 *
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);
}    

0 个答案:

没有答案