Login.Java
package Login;
public class Login extends Application{
@Override
public void start(Stage stage)throws Exception{
Parent root = (Parent) FXMLLoader.load(getClass().getResource("Login.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Library Management System");
stage.show();}
public static void main(String[] args){
launch(args);} }
LoginController.java
package Login;
public class LoginController implements Initializable {
Librarian l1=new Librarian();
@FXML
private JFXTextField username;
@FXML
private JFXPasswordField password;
@FXML
private JFXButton Loginbutton;
@FXML
private JFXButton CancelButton;
@Override
public void initialize(URL url, ResourceBundle rb) {
}
@FXML
private void LibrarianLogin(ActionEvent event) throws SQLException {
if(l1.isLogin(username.getText(),password.getText())){
Stage stage = (Stage) this.Loginbutton.getScene().getWindow();
stage.close();
adminLogin();
}
}
@FXML
private void handleCancelBtnAction(ActionEvent event) {
}
public void adminLogin()
{
try{
Stage adminstage = new Stage();
FXMLLoader adminLoader = new FXMLLoader();
Pane adminroot = (Pane)adminLoader.load(getClass().getResource("/Librarian/admin.fxml").openStream());
AdminController adminController = (AdminController)adminLoader.getController();
Scene scene =new Scene(adminroot);
adminstage.setScene(scene);
adminstage.setTitle("Admin Dashboard");
adminstage.show();
}
catch (IOException e){
}
}
}
按下登录按钮时会发生错误!我不知道该怎么办!!! 当我用空的fxml替换admin.fxml时,当我点击登录按钮时会出现另一个窗口! 除了这些警告之外,我没有任何错误:
Apr 21, 2018 1:38:07 AM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 9.0.1 by JavaFX
runtime of version 8.0.161
Apr 21, 2018 1:38:12 AM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 9.0.1 by JavaFX
runtime of version 8.0.161