我的代码不起作用,因为我认为module-info.java文件中存在问题。
我不知道为JavaFX添加哪些模块以及如何添加。我是Modules的新人。
我总是得到java.lang.reflect.invocationTargetException
。
我添加了javafx-library。
module FXML_richtige_Module {
requires transitive javafx.controls;
requires transitive javafx.graphics;
requires javafx.fxml;
opens application;
exports application;
}
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class RegistrationFormApplication extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getclass().getResource("registration_form.fxml"));
primaryStage.setTitle("Registration Form FXML Application");
primaryStage.setScene(new Scene(root,800,500));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
package application;
import javafx.scene.control.Alert;
import javafx.stage.Window;
public class AlertHelper {
public static void showAlert(Alert.AlertType alertType,Window owner,String title,String message) {
Alert alert = new Alert(alertType);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.initOwner(owner);
alert.show();
}
}
package application;
import javafx.event.actionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Window;
public class RegistrationFormController {
@FXML
private TextField nameField;
@FXML
private TextField emailField;
@FXML
private PasswordField passwordField;
@FXML
private Button submitButton;
@FXML
protected void handleSubmitButtonaction(actionEvent event) {
Window owner = submitButton.getScene().getWindow();
if(nameField.getText().isEmpty()) {
AlertHelper.showAlert(Alert.AlertType.ERROR,owner,"Form Error!","Please enter your name");
return;
}
if(emailField.getText().isEmpty()) {
AlertHelper.showAlert(Alert.AlertType.ERROR,"Please enter your email id");
return;
}
if(passwordField.getText().isEmpty()) {
AlertHelper.showAlert(Alert.AlertType.ERROR,"Please enter a password");
return;
}
AlertHelper.showAlert(Alert.AlertType.CONFIRMATION,"Registration Successful!","Welcome " + nameField.getText());
}
}