JavaFX - 单击按钮后的新窗口

时间:2015-12-15 15:37:30

标签: java eclipse javafx

我正在编写桌面应用程序(虚拟诊所),输入登录名和密码后我想点击按钮(登录)后会出现所有选项的新窗口,但我遇到了问题。当我点击按钮它导致错误“位置是必需的”,但在FXML文件中我标记了正确的控制器(我猜),这是一个代码:

Login.fxml和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">

主:

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();
    }

}
}

我做错了什么?

0 个答案:

没有答案