2

I'm writing desktop app (virtual clinic), and after enter login and password I want in order to after click the button (log in) new window with all options will appear, but I got a problem with that. When I clicked the button It causes error "Location is required", but in FXML files I marked properly controllers (I guess), here is a code:

first lines in Login.fxml and Home.fxml:

<BorderPane xmlns="http://javafx.com/javafx/8"  xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.LoginController">

<BorderPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="controller.HomeController">

Main:

package application;



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


public class Main extends Application {
@Override
public void start(Stage primaryStage) {
    try {
        BorderPane root =  (BorderPane)FXMLLoader.load(getClass().getResource("/view/Login.fxml"));
        Scene scene = new Scene(root,280,280);
        scene.getStylesheets().add(getClass().getResource("/view/application.css").toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.show();
        primaryStage.setTitle("Przychodnia");
        primaryStage.setResizable(false);
    } catch(Exception e) {
        e.printStackTrace();
    }
}

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

LoginController:

package controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class LoginController {

@FXML
TextField loginField;

@FXML
PasswordField passwordField;

@FXML
Button logInButton;

@FXML
public void enterLoginAndPassword(ActionEvent event) {

}

@FXML
public void logIn(ActionEvent event) {

    BorderPane root;

    try {
        root = FXMLLoader.load(getClass().getClassLoader().getResource("/view/Home.fxml"));
        Stage stage = new Stage();
        stage.setTitle("Przychodnia");
        stage.setScene(new Scene(root, 530, 750));
        stage.show();
    } catch (Exception e) {
        e.printStackTrace();
    }

}
}

What am I doing wrong?

dante
  • 393
  • 1
  • 15
  • 31

0 Answers0