Stand 14.11.21
This commit is contained in:
parent
aa038cc036
commit
7ed8afba9a
BIN
DigitalesFreundebuch/freunde.db
Normal file
BIN
DigitalesFreundebuch/freunde.db
Normal file
Binary file not shown.
@ -6,10 +6,7 @@ import javafx.event.EventHandler;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ColorPicker;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.effect.DropShadow;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
@ -19,18 +16,40 @@ import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.text.TextAlignment;
|
||||
import javafx.stage.Stage;
|
||||
import java.sql.*;
|
||||
|
||||
public class Main extends Application {
|
||||
|
||||
// Datenbankvariablen
|
||||
// Datenbankkonstanten
|
||||
// Datenbankname
|
||||
public static final String db_name = "freunde.db";
|
||||
|
||||
// Tabellenname
|
||||
public static final String table_freunde = "freunde";
|
||||
|
||||
// Connectionpfad
|
||||
public static final String connection_string = "jdbc:sqlite:.\\" + db_name;
|
||||
|
||||
// Freund in Datenbank hinzufügen
|
||||
private static void createFreund(Statement statement, String vorname, String nachname, String geburtstag, String wohnort, String spitzname, String lieblingsfarbe, String lieblingsessen, String lieblingstier, String hobbys, String lieblingsmusik, String lieblingsfilm, String traumauto, String traumberuf, String likeYou, String tellMe) throws SQLException {
|
||||
statement.execute("INSERT INTO " + table_freunde + " VALUES " + "('" + vorname + "', '" + nachname + "', '" + geburtstag + "', '" + wohnort + "', '" + spitzname + "', '" + lieblingsfarbe + "', '" + lieblingsessen + "', '" + lieblingstier + "', '" + hobbys + "', '" + lieblingsmusik + "', '" + lieblingsfilm + "', '" + traumauto + "', '" + traumberuf + "', '" + likeYou + "', '" + tellMe + "')");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception{
|
||||
// Layout / Scene
|
||||
|
||||
// Datenbank Connection ------------------------------------------------------------------------------------------------------------------------
|
||||
// Connection aufbauen
|
||||
Connection connection = DriverManager.getConnection(connection_string);
|
||||
|
||||
// CRUD Befehle ausführen können
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
// Layout / Scene ------------------------------------------------------------------------------------------------------------------------------
|
||||
VBox root = new VBox();
|
||||
Scene scene = new Scene(root, 300,400);
|
||||
scene.getStylesheets().add("sample/application.css");
|
||||
@ -86,13 +105,338 @@ public class Main extends Application {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
// Layout / Scene
|
||||
GridPane root2 = new GridPane();
|
||||
Scene scene2 = new Scene(root2, 800,500);
|
||||
StackPane rahmen = new StackPane();
|
||||
rahmen.setStyle("-fx-background-color: white;");
|
||||
|
||||
HBox root3 = new HBox();
|
||||
Scene scene3 = new Scene(rahmen, 800,500);
|
||||
VBox seiteLinks = new VBox();
|
||||
VBox seiteRechts = new VBox();
|
||||
seiteLinks.setStyle("-fx-background-color: transparent;");
|
||||
seiteRechts.setStyle("-fx-background-color: transparent;");
|
||||
|
||||
// Rahmen ############################################################
|
||||
|
||||
// Rechteck
|
||||
Rectangle rand = new Rectangle();
|
||||
rand.setHeight(950);
|
||||
rand.setWidth(1650);
|
||||
rand.setFill(Color.TRANSPARENT);
|
||||
rand.setStroke(Color.WHITE);
|
||||
rand.setStrokeWidth(5);
|
||||
|
||||
// Seite Links ############################################################
|
||||
// Image
|
||||
Image img = new Image("sample/bildIcon.jpg");
|
||||
ImageView view = new ImageView(img);
|
||||
|
||||
view.setOnMouseClicked(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
// File Chooser
|
||||
}
|
||||
});
|
||||
|
||||
// Rechteck
|
||||
Rectangle viereck = new Rectangle();
|
||||
viereck.setHeight(250);
|
||||
viereck.setWidth(200);
|
||||
viereck.setFill(Color.TRANSPARENT);
|
||||
viereck.setStroke(Color.BLACK);
|
||||
viereck.setStrokeWidth(5);
|
||||
|
||||
// StackPane
|
||||
StackPane stackPane = new StackPane();
|
||||
|
||||
// In StackPane hinzufügen
|
||||
stackPane.getChildren().addAll(viereck, view);
|
||||
stackPane.setMaxHeight(250);
|
||||
stackPane.setMaxWidth(200);
|
||||
|
||||
// VBoxen
|
||||
VBox grundedatenRechts = new VBox();
|
||||
|
||||
// HBoxen
|
||||
HBox grunddaten = new HBox();
|
||||
HBox vornameBox = new HBox();
|
||||
HBox nachnameBox = new HBox();
|
||||
HBox geburtstagBox = new HBox();
|
||||
HBox wohnortBox = new HBox();
|
||||
HBox spitznameBox = new HBox();
|
||||
HBox lieblingsfarbeBox = new HBox();
|
||||
HBox lieblingsessenBox = new HBox();
|
||||
HBox lieblingstierBox = new HBox();
|
||||
HBox hobbysBox = new HBox();
|
||||
|
||||
// Circle
|
||||
HBox kreisPosi = new HBox();
|
||||
Circle circle = new Circle();
|
||||
circle.setRadius(20);
|
||||
circle.setFill(Color.BLUE);
|
||||
kreisPosi.getChildren().add(circle);
|
||||
|
||||
// Button Effekte
|
||||
view.setOnMouseEntered(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
view.setEffect(shadow);
|
||||
}
|
||||
});
|
||||
|
||||
view.setOnMouseExited(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
view.setEffect(null);
|
||||
}
|
||||
});
|
||||
|
||||
// Button Klick
|
||||
view.setOnMouseClicked(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
// Hier soll sich ein Dateiauswahlfenster öffnen wo das Bild ausgewählt werden kann
|
||||
}
|
||||
});
|
||||
|
||||
// Label
|
||||
Label vornameLabel = new Label("Vorname");
|
||||
Label nachnameLabel = new Label("Nachname");
|
||||
Label geburtstagLabel = new Label("Geburtstag");
|
||||
Label wohnortLabel = new Label("Wohnort");
|
||||
Label spitznameLabel = new Label("Spitzname");
|
||||
Label lieblingsfarbeLabel = new Label("Lieblingsfarbe");
|
||||
Label lieblingsessenLabel = new Label("Lieblingsessen");
|
||||
Label lieblingstierLabel = new Label("Lieblingstier");
|
||||
Label hobbysLabel = new Label("Hobbys");
|
||||
|
||||
// Label Positionierung
|
||||
vornameLabel.setPadding(new Insets(0, 69, 0, 0));
|
||||
nachnameLabel.setPadding(new Insets(0, 54, 0, 0));
|
||||
geburtstagLabel.setPadding(new Insets(0, 45, 0, 0));
|
||||
wohnortLabel.setPadding(new Insets(0, 67, 0, 0));
|
||||
spitznameLabel.setPadding(new Insets(0, 107, 0, 0));
|
||||
lieblingsfarbeLabel.setPadding(new Insets(0, 71, 0, 0));
|
||||
lieblingsessenLabel.setPadding(new Insets(0, 71, 0, 0));
|
||||
lieblingstierLabel.setPadding(new Insets(0, 88, 0, 0));
|
||||
hobbysLabel.setPadding(new Insets(0, 135, 0, 0));
|
||||
|
||||
// Label Schriftart / Schriftgröße
|
||||
vornameLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
nachnameLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
geburtstagLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
wohnortLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
spitznameLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
lieblingsfarbeLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
lieblingsessenLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
lieblingstierLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
hobbysLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
|
||||
// Text
|
||||
Text vornameEintrag = new Text();
|
||||
Text nachnameEintrag = new Text();
|
||||
Text geburtstagEintrag = new Text();
|
||||
Text wohnortEintrag = new Text();
|
||||
Text spitznameEintrag = new Text();
|
||||
Text lieblingsessenEintrag = new Text();
|
||||
Text lieblingstierEintrag = new Text();
|
||||
Text hobbysEintrag = new Text();
|
||||
|
||||
// TextBreite
|
||||
vornameEintrag.setWrappingWidth(200); // Damit der Abstand zwischen rechts und links wieder passt
|
||||
|
||||
// Schriftart - größe
|
||||
vornameEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
nachnameEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
geburtstagEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
wohnortEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
spitznameEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
lieblingsessenEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
lieblingstierEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
hobbysEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
|
||||
// In vornameBox, nachnameBox, geburtstagBox, wohnortBox, spitznameBox, lieblingsfarbeBox, lieblingsessenBox, lieblingstierBox, hobbysBox hinzu
|
||||
vornameBox.getChildren().addAll(vornameLabel, vornameEintrag );
|
||||
nachnameBox.getChildren().addAll(nachnameLabel, nachnameEintrag );
|
||||
geburtstagBox.getChildren().addAll(geburtstagLabel, geburtstagEintrag);
|
||||
wohnortBox.getChildren().addAll(wohnortLabel, wohnortEintrag );
|
||||
spitznameBox.getChildren().addAll(spitznameLabel, spitznameEintrag );
|
||||
lieblingsfarbeBox.getChildren().addAll(lieblingsfarbeLabel, kreisPosi); // lieblingsfarbe
|
||||
lieblingsfarbeBox.setAlignment(Pos.CENTER_LEFT);
|
||||
lieblingsessenBox.getChildren().addAll(lieblingsessenLabel, lieblingsessenEintrag);
|
||||
lieblingstierBox.getChildren().addAll(lieblingstierLabel, lieblingstierEintrag );
|
||||
hobbysBox.getChildren().addAll(hobbysLabel, hobbysEintrag );
|
||||
|
||||
// In VBox grunddatenRechts hinzu
|
||||
grundedatenRechts.getChildren().addAll(vornameBox, nachnameBox, geburtstagBox, wohnortBox);
|
||||
grundedatenRechts.setAlignment(Pos.CENTER);
|
||||
grundedatenRechts.setSpacing(35);
|
||||
grundedatenRechts.setPadding(new Insets(50));
|
||||
|
||||
// In HBox Grunddaten hinzu
|
||||
grunddaten.getChildren().addAll(stackPane, grundedatenRechts);
|
||||
grunddaten.setAlignment(Pos.CENTER_LEFT);
|
||||
|
||||
// In VBox seiteLinks hinzu
|
||||
seiteLinks.getChildren().addAll(grunddaten, spitznameBox, lieblingsfarbeBox, lieblingsessenBox, lieblingstierBox, hobbysBox);
|
||||
seiteLinks.setSpacing(35);
|
||||
|
||||
// Seite Rechts ############################################################
|
||||
// HBoxen
|
||||
HBox lieblingsmusikBox = new HBox();
|
||||
HBox lieblingsfilmBox = new HBox();
|
||||
HBox traumautoBox = new HBox();
|
||||
HBox traumberufBox = new HBox();
|
||||
HBox likeYouBox = new HBox();
|
||||
HBox tellMeBox = new HBox();
|
||||
HBox buttonAuswahl = new HBox();
|
||||
|
||||
// Label
|
||||
Label lieblingsmusikLabel = new Label("Lieblingsmusik");
|
||||
Label lieblingsfilmLabel = new Label("Lieblingsfilm");
|
||||
Label traumautoLabel = new Label("Traumauto");
|
||||
Label traumberufLabel =new Label("Traumberuf");
|
||||
Label likeYouLabel = new Label("Das mag ich\nan dir");
|
||||
Label tellMeLabel = new Label("Das wolle\nich dir immer\nschon sagen");
|
||||
|
||||
// Label Schriftart / Schriftgröße
|
||||
lieblingsmusikLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
lieblingsfilmLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
traumautoLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
traumberufLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
likeYouLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
tellMeLabel.setFont(new Font("Comic Sans MS", 20));
|
||||
|
||||
// TextArea
|
||||
Text lieblingsmusikEintrag = new Text();
|
||||
Text lieblingsfilmEintrag = new Text();
|
||||
Text traumautoEintrag = new Text();
|
||||
Text traumberufEintrag = new Text();
|
||||
Text likeYouEintrag = new Text(); // Beschränken auf 80 Zeichen
|
||||
Text tellMeEintrag = new Text(); // Beschränken auf 305 Zeichen
|
||||
|
||||
// Schriftart Text
|
||||
lieblingsmusikEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
lieblingsfilmEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
traumautoEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
traumberufEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
likeYouEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
tellMeEintrag.setFont(new Font("Comic Sans MS", 20));
|
||||
|
||||
// Textumbruch
|
||||
likeYouEintrag.setWrappingWidth(400);
|
||||
tellMeEintrag.setWrappingWidth(400);
|
||||
|
||||
// Button
|
||||
Button bearbeiten = new Button("Bearbeiten");
|
||||
Button abbruch = new Button("Abbruch");
|
||||
Button loeschen = new Button("Löschen");
|
||||
buttonAuswahl.setSpacing(10.0);
|
||||
buttonAuswahl.setAlignment(Pos.CENTER_RIGHT);
|
||||
|
||||
// Button Interaktion
|
||||
// Speichern Interaktion ############################################################
|
||||
bearbeiten.setOnMouseEntered(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
bearbeiten.setEffect(shadow);
|
||||
}
|
||||
});
|
||||
bearbeiten.setOnMouseExited(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
bearbeiten.setEffect(null);
|
||||
}
|
||||
});
|
||||
bearbeiten.setOnMouseClicked(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
bearbeiten.setText("Speichern");
|
||||
loeschen.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
// Abbruch Interaktion ##############################################################
|
||||
abbruch.setOnMouseEntered(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
abbruch.setEffect(shadow);
|
||||
}
|
||||
});
|
||||
abbruch.setOnMouseExited(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
abbruch.setEffect(null);
|
||||
}
|
||||
});
|
||||
abbruch.setOnMouseClicked(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
});
|
||||
|
||||
// Löschen Interaktion ##############################################################
|
||||
loeschen.setOnMouseEntered(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
loeschen.setEffect(shadow);
|
||||
}
|
||||
});
|
||||
loeschen.setOnMouseExited(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
loeschen.setEffect(null);
|
||||
}
|
||||
});
|
||||
loeschen.setOnMouseClicked(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// Label und TextField Positionierung
|
||||
lieblingsmusikLabel.setPadding(new Insets(0, 54, 0, 0));
|
||||
lieblingsfilmLabel.setPadding(new Insets(0, 69, 0, 0));
|
||||
traumautoLabel.setPadding(new Insets(0, 88, 0, 0));
|
||||
traumberufLabel.setPadding(new Insets(0, 75, 0, 0));
|
||||
likeYouLabel.setPadding(new Insets(0, 77, 0, 0));
|
||||
tellMeLabel.setPadding(new Insets(0, 64, 0, 0));
|
||||
|
||||
// HBoxen positionieren
|
||||
likeYouBox.setPadding(new Insets(50,0,0,0));
|
||||
likeYouBox.setAlignment(Pos.CENTER_LEFT);
|
||||
tellMeBox.setPadding(new Insets(5,0,0,0));
|
||||
tellMeBox.setMinHeight(250);
|
||||
tellMeBox.setMaxHeight(250);
|
||||
tellMeBox.setAlignment(Pos.CENTER_LEFT);
|
||||
|
||||
// In HBoxen hinzu
|
||||
lieblingsmusikBox.getChildren().addAll(lieblingsmusikLabel, lieblingsmusikEintrag);
|
||||
lieblingsfilmBox.getChildren().addAll(lieblingsfilmLabel, lieblingsfilmEintrag);
|
||||
traumautoBox.getChildren().addAll(traumautoLabel, traumautoEintrag);
|
||||
traumberufBox.getChildren().addAll(traumberufLabel, traumberufEintrag);
|
||||
likeYouBox.getChildren().addAll(likeYouLabel, likeYouEintrag);
|
||||
tellMeBox.getChildren().addAll(tellMeLabel, tellMeEintrag);
|
||||
buttonAuswahl.getChildren().addAll(loeschen, bearbeiten, abbruch);
|
||||
|
||||
// In Seite Rechts hinzu
|
||||
seiteRechts.getChildren().addAll(lieblingsmusikBox, lieblingsfilmBox, traumautoBox, traumberufBox, likeYouBox, tellMeBox, buttonAuswahl);
|
||||
seiteRechts.setSpacing(35);
|
||||
seiteRechts.setPadding(new Insets(50,0,0,0));
|
||||
|
||||
// Layout ##################################################################
|
||||
// Ins Layout einfügen
|
||||
root3.getChildren().addAll(seiteLinks, seiteRechts);
|
||||
root3.setPadding(new Insets(150));
|
||||
root3.setSpacing(150);
|
||||
root3.setAlignment(Pos.CENTER);
|
||||
root3.setStyle("-fx-background-color: transparent;");
|
||||
rahmen.getChildren().addAll(rand, root3);
|
||||
|
||||
// Stage
|
||||
primaryStage.setScene(scene2);
|
||||
primaryStage.setScene(scene3);
|
||||
primaryStage.setFullScreen(true);
|
||||
primaryStage.show();
|
||||
}
|
||||
@ -381,7 +725,16 @@ public class Main extends Application {
|
||||
speichern.setOnMouseClicked(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
|
||||
if (vorname.getText().isEmpty() || nachname.getText().isEmpty() || geburtstag.getText().isEmpty() || wohnort.getText().isEmpty() || spitzname.getText().isEmpty() || lieblingsessen.getText().isEmpty() || lieblingstier.getText().isEmpty() || hobbys.getText().isEmpty() || lieblingsmusik.getText().isEmpty() || lieblingsfilm.getText().isEmpty() || traumauto.getText().isEmpty() || traumberuf.getText().isEmpty() || likeYou.getText().isEmpty() || tellMe.getText().isEmpty()) {
|
||||
} else {
|
||||
try {
|
||||
createFreund(statement, vorname.getText(), nachname.getText(), geburtstag.getText(), wohnort.getText(), spitzname.getText(), colorPicker.getValue().toString(), lieblingsessen.getText(), lieblingstier.getText(), hobbys.getText(), lieblingsmusik.getText(), lieblingsfilm.getText(), traumauto.getText(), traumberuf.getText(), likeYou.getText(), tellMe.getText());
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
abbruch.setOnMouseEntered(new EventHandler<MouseEvent>() {
|
||||
@ -564,7 +917,4 @@ public class Main extends Application {
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,3 @@
|
||||
.root {
|
||||
.seiteLinks {
|
||||
"-fx-background-color: transparent;"
|
||||
}
|
Loading…
Reference in New Issue
Block a user