1

I'm writing this post because I came across one problem - switching scenes in JavaFx. I've been learning how to do it for a while but I still don't understand it. Can you help me with this issue?

In the controller class I want to switch scenes after typing the correct login and password - LoginButtonClicked method, tu.fxml is my new scene constructed in Scene Builder.

I will be also very grateful if you could tell me if I'm making any mistakes with this code =D. For example a badly constructed controller etc. Thanks in advance!

Main class:

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Endomondo By Michael");
        primaryStage.setScene(new Scene(root, 800, 600));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

Controller class:

package sample;


public class LoginController {
    @FXML
    public TextField login,password;
    Stage MainStage;
    Scene scene;


    public void LoginButtonClicked(ActionEvent event) throws IOException {
        if(login.getText().equals("yes")&&password.getText().equals("yes"))
        {
            MainStage = FXMLLoader.load(getClass().getResource("tu.fxml"));
        }
        else
        {
            System.out.print("no");
        }

    }

}
EM-Creations
  • 4,195
  • 4
  • 40
  • 56
Mich44
  • 95
  • 1
  • 1
  • 7
  • Thanks for intrest! I think now my post is readable. – Mich44 Aug 02 '15 at 14:41
  • 1
    It's not clear what you're asking about [*Ensemble*](http://www.oracle.com/technetwork/java/javase/overview/javafx-samples-2158687.html) `FXML-LoginDemo`, which is a complete example. – trashgod Aug 02 '15 at 15:49

0 Answers0