Hello i have the issue that my programm is not working. I always get this console message in Intelij (Java):
/Users/samvolzke/Library/Mobile Documents/com~apple~CloudDocs/Documents/Programmieren/Java/Intelij Projects/Vocabeln/src/main/java/org/example/vocabeln/HelloController.java:3:14
java: Package javafx.event ist nicht sichtbar
(Package javafx.event wird in Modul javafx.base deklariert, das nicht im Moduldiagramm enthalten ist)
Has anybody an idea why the program do not work?
Hear are my classes:
package org.example.vocabeln;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.Hyperlink;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
public class HelloController {
@FXML
void ConfirmLogin(MouseEvent event) {
}
@FXML
void ConfirmPasswort(MouseEvent event) {
}
@FXML
void ConfirmUserName(MouseEvent event) {
}
@FXML
void CreateAccount(ActionEvent event) {
}
void createAccount(ActionEvent event) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/org/example/vocabeln/CreateAccount.fxml"));
Parent root = loader.load();
Stage currentStage = (Stage)((Hyperlink)event.getSource()).getScene().getWindow();
currentStage.close();
}
catch (Exception e){
e.printStackTrace();
}
}
}
package org.example.vocabeln;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class DatabaseManager {
public void insertUser(User user) {
// Stelle sicher, dass der JDBC-Treiber geladen ist.
try {
Class.forName("org.postgresql.Driver");
// Verwende try-with-resources für die automatische Ressourcenfreigabe.
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/MyDatabase", "postgres", "....");
PreparedStatement preparedStatement = connection.prepareStatement(
"INSERT INTO CUSTOMER_REGISTRATION (FIRST_NAME, LAST_NAME, USERNAME, BIRTHDATE, EMAIL, PASSWORD) VALUES (?, ?, ?, ?, ?, ?)")) {
preparedStatement.setString(1, user.getVorname());
preparedStatement.setString(2, user.getNachname());
preparedStatement.setString(3, user.getUsername());
preparedStatement.setDate(4, Date.valueOf(user.getGeburtsdatum())); // Konvertiere LocalDate in java.sql.Date
preparedStatement.setString(5, user.getEmail());
preparedStatement.setString(6, user.getPasswort());
int rowsAffected = preparedStatement.executeUpdate();
if (rowsAffected > 0) {
System.out.println("Benutzer erfolgreich in die Datenbank eingefügt!");
} else {
System.out.println("Fehler beim Einfügen des Benutzers in die Datenbank.");
}
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
}
package org.example.vocabeln;
import org.mindrot.jbcrypt.BCrypt;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
public class User {
private String vorname;
private String nachname;
private String username;
private LocalDate geburtsdatum; // Datentyp zu LocalDate ändern
private String email;
private String passwort;
public User(String vorname, String nachname, String username, String geburtsdatum, String email, String passwort) {
this.vorname = vorname;
this.nachname = nachname;
this.username = username;
this.email = email;
// Datumskonvertierung
setGeburtsdatum(geburtsdatum);
// Hashen des Passworts
this.passwort = hashPassword(passwort);
}
public String getVorname() {
return vorname;
}
public void setVorname(String vorname) {
this.vorname = vorname;
}
public String getNachname() {
return nachname;
}
public void setNachname(String nachname) {
this.nachname = nachname;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public LocalDate getGeburtsdatum() {
return geburtsdatum;
}
// Setter, der eine Zeichenfolge annimmt und sie in LocalDate umwandelt
public void setGeburtsdatum(String geburtsdatum) {
try {
this.geburtsdatum = LocalDate.parse(geburtsdatum, DateTimeFormatter.ofPattern("dd.MM.yyyy"));
} catch (DateTimeParseException e) {
System.out.println("Fehler bei der Formatierung des Datums. Bitte sicherstellen, dass das Datum im Format 'dd.MM.yyyy' eingegeben wird.");
e.printStackTrace();
}
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
private String hashPassword(String plainTextPassword) {
return BCrypt.hashpw(plainTextPassword, BCrypt.gensalt());
}
public String getPasswort() {
return passwort;
}
public void setPasswort(String passwort) {
this.passwort = hashPassword(passwort);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.example.vocabeln.RegistrationController">
<left>
<AnchorPane prefHeight="500.0" prefWidth="350.0" style="-fx-background-color: #003366;" BorderPane.alignment="CENTER" />
</left>
<center>
<AnchorPane prefHeight="500.0" prefWidth="357.0" BorderPane.alignment="CENTER">
<children>
<Text layoutX="67.0" layoutY="55.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Erstellung deines Accounts">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Text>
<TextField fx:id="vornameField" layoutX="95.0" layoutY="87.0" promptText="Vorname" style="-fx-background-color: transparent; -fx-border-color: #003366; -fx-border-width: 0px 0px 2px 0px;" />
<TextField fx:id="nachnameField" layoutX="95.0" layoutY="128.0" promptText="Nachname" style="-fx-background-color: transparent; -fx-border-color: #003366; -fx-border-width: 0px 0px 2px 0px;" />
<TextField fx:id="GeburtsdatumField" layoutX="95.0" layoutY="237.0" promptText="Geburtsdatum" style="-fx-background-color: transparent; -fx-border-color: #003366; -fx-border-width: 0px 0px 2px 0px;" />
<TextField fx:id="EMailAdresseField" layoutX="95.0" layoutY="276.0" promptText="E-Mail Adresse" style="-fx-background-color: transparent; -fx-border-color: #003366; -fx-border-width: 0px 0px 2px 0px;" />
<PasswordField fx:id="PasswordField" layoutX="95.0" layoutY="349.0" promptText="Passwort" style="-fx-background-color: transparent; -fx-border-color: #003366; -fx-border-width: 0px 0px 2px 0px;" />
<PasswordField fx:id="RepeatPasswordField" layoutX="95.0" layoutY="384.0" promptText="Wiederholen" style="-fx-background-color: transparent; -fx-border-color: #003366; -fx-border-width: 0px 0px 2px 0px;" />
<TextField fx:id="usernameField" layoutX="95.0" layoutY="197.0" promptText="Username" style="-fx-background-color: transparent; -fx-border-color: #003366; -fx-border-width: 0px 0px 2px 0px;" />
<Button fx:id="registrateButon" layoutX="128.0" layoutY="444.0" mnemonicParsing="false" onAction="#RegistrierungAbgeschlossen" style="-fx-background-color: #003366; -fx-text-fill: white;" text="Registrieren" />
</children>
</AnchorPane>
</center>
</BorderPane>
<?xml version="1.0" encoding="UTF-8"?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Hyperlink?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.example.vocabeln.HelloController">
<left>
<AnchorPane prefHeight="500.0" prefWidth="350.0" style="-fx-background-color: #003366;" BorderPane.alignment="CENTER">
<children>
<FontAwesomeIconView glyphName="BOOK" fill="WHITE" layoutX="140.0" layoutY="172.0" size="75"/>
<Text fill="WHITE" layoutX="114.0" layoutY="220.0" strokeType="OUTSIDE" strokeWidth="0.0" text="StudiBuddy">
<font>
<Font size="25.0" />
</font>
</Text>
</children>
</AnchorPane>
</left>
<right>
<AnchorPane prefHeight="500.0" prefWidth="458.0" BorderPane.alignment="CENTER">
<children>
<TextField layoutX="95.0" layoutY="200.0" onMouseExited="#ConfirmUserName" promptText="User Name" style="-fx-background-color: transparent; -fx-border-color: #003366; -fx-border-width: 0px 0px 2px 0px;" />
<PasswordField layoutX="95.0" layoutY="242.0" onMouseExited="#ConfirmPasswort" promptText="Passwort" style="-fx-background-color: transparent; -fx-border-color: #003366; -fx-border-width: 0px 0px 2px 0px;" />
<Button layoutX="129.0" layoutY="295.0" mnemonicParsing="false" onMouseClicked="#ConfirmLogin" prefHeight="34.0" prefWidth="84.0" style="-fx-background-color: #003366; -fx-text-fill: white;" text="Login" />
<Hyperlink layoutX="103.0" layoutY="347.0" style="-fx-background-color: transparent; -fx-text-fill: #003366;" text="Passwort vergessen?" />
<FontAwesomeIconView glyphName="USERS" fill="#003366" layoutX="150.0" layoutY="107.0" size="35" />
<Text layoutX="121.0" layoutY="154.0" strokeType="OUTSIDE" strokeWidth="0.0" text="User Login">
<font>
<Font size="22.0" />
</font>
</Text>
<FontAwesomeIconView glyphName="USER" fill="#003366" layoutX="55.0" layoutY="219.0" size="17" />
<FontAwesomeIconView glyphName="KEY" fill="#003366" layoutX="55.0" layoutY="261.0" size="17" />
<Hyperlink layoutX="115.0" layoutY="378.0" onAction="#CreateAccount" style="-fx-background-color: transparent; -fx-text-fill: #003366;" text="Account erstellen" />
</children>
</AnchorPane>
</right>
</BorderPane>
package org.example.vocabeln;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
public class RegistrationController {
@FXML
private TextField EMailAdresseField;
@FXML
private TextField GeburtsdatumField;
@FXML
private PasswordField PasswordField;
@FXML
private PasswordField RepeatPasswordField;
@FXML
private TextField nachnameField;
@FXML
private TextField usernameField;
@FXML
private TextField vornameField;
@FXML
void RegistrierungAbgeschlossen(ActionEvent event) {
try {
String vorname = vornameField.getText();
String nachname = nachnameField.getText();
String username = usernameField.getText();
String geburtsdatum = GeburtsdatumField.getText();
String email = EMailAdresseField.getText();
String passwort = PasswordField.getText();
User user = new User(vorname, nachname, username, geburtsdatum, email, passwort);
DatabaseManager dbManager = new DatabaseManager();
dbManager.insertUser(user);
System.out.println("Benutzer erfolgreich in die Datenbank eingefügt.");
} catch (Exception e) {
e.printStackTrace();
System.err.println("Fehler bei der Registrierung: " + e.getMessage());
}
}
}
package org.example.vocabeln;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
stage.setTitle("Hello!");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
user24938703 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.