From 3d4e66828e1d50c99f1ca003c624195d19ed415a Mon Sep 17 00:00:00 2001 From: JunkJumper Date: Mon, 27 Apr 2020 14:04:23 +0200 Subject: [PATCH 1/3] Database Management classes #4 --- src/database/QueryGenerator.java | 21 ++++++++++++ src/database/Record.java | 40 +++++++++++++++++++++++ src/database/Table.java | 56 ++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 src/database/QueryGenerator.java create mode 100644 src/database/Record.java create mode 100644 src/database/Table.java diff --git a/src/database/QueryGenerator.java b/src/database/QueryGenerator.java new file mode 100644 index 0000000..1821da9 --- /dev/null +++ b/src/database/QueryGenerator.java @@ -0,0 +1,21 @@ +package database; + +public class QueryGenerator { + + public static String AllFrom(String table) { + return "SELECT * FROM " + getTable(table); + } + + public static String WithId(String table, int d) { + return "SELECT * FROM " + getTable(table) + "WHERE id =" + d; + } + + public static String WithName(String s, String name) { + return "SELECT * FROM " + getTable(s) + "WHERE nom ='" + name + "'"; + } + + public static String getTable(String s) { + return "public.\"" + s + "\""; + } + +} diff --git a/src/database/Record.java b/src/database/Record.java new file mode 100644 index 0000000..6f2aad1 --- /dev/null +++ b/src/database/Record.java @@ -0,0 +1,40 @@ +package database; + +public class Record { + + private int id; + private String nom; + private byte[] img; + + public Record() { + this(0, null, null); + } + + public Record(String n, byte[] b) { + this(0, n, b); + } + + public Record(String number, String n, byte[] b) { + this(Integer.parseInt(number), n, b); + } + + public Record(int i, String n, byte[] b) { + this.id = i; + this.nom = n; + this.img = b; + } + + public int getId() { + return id; + } + + public String getNom() { + return nom; + } + + public byte[] getImg() { + return img; + } + + +} diff --git a/src/database/Table.java b/src/database/Table.java new file mode 100644 index 0000000..eb92c15 --- /dev/null +++ b/src/database/Table.java @@ -0,0 +1,56 @@ +package database; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +public class Table { + + private String name; + private List list = new ArrayList(); + + public Table(String JavaTableName) { + this.name = JavaTableName; + } + + public void remplirTable(String DatabaseTableName) { + try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/ShadowHunterDatabase", "shManager", "shadowhunter1234")) { //notre utilisateur que l'on utilisera (: + + System.out.println("Connected to PostgreSQL database!"); + Statement statement = connection.createStatement(); + System.out.println("Reading records..."); + ResultSet retour = statement.executeQuery(QueryGenerator.AllFrom(DatabaseTableName)); + while (retour.next()) { + Record r = new Record(retour.getString("id"), retour.getString("nom"), retour.getBytes("image")); + list.add(r); + //System.out.printf("%-20.30s %-30.30s %-20.30s%n", retour.getString("id"), retour.getString("nom"), retour.getBytes("image")); + } + + } catch (SQLException e) { + System.out.println("Connection failure."); + e.printStackTrace(); + } + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getList() { + return list; + } + + + + + + +} From aa73c3c6ea69924c0f7fb424f126df7f4b53cc0c Mon Sep 17 00:00:00 2001 From: Bastien NOEL Date: Mon, 27 Apr 2020 14:32:50 +0200 Subject: [PATCH 2/3] correction des boutons de choix des joueurs --- src/ihm/Main.java | 2 +- src/ihm/controller/PlateauController.java | 23 +++++------------ src/ihm/controller/PlayersController.java | 2 +- src/ihm/ressources/Choix_joueur.fxml | 30 +++++++++++------------ src/ihm/ressources/Plateau.fxml | 17 ------------- 5 files changed, 23 insertions(+), 51 deletions(-) diff --git a/src/ihm/Main.java b/src/ihm/Main.java index ea9fd09..e2ad2e7 100644 --- a/src/ihm/Main.java +++ b/src/ihm/Main.java @@ -12,7 +12,7 @@ public class Main extends Application { public void start(Stage primaryStage) throws Exception { System.out.println("Lancement de l'application"); - Pane root = FXMLLoader.load(getClass().getResource("ressources/des.fxml")); // "ressources/Jouer_tour(1)lancer_des.fxml" + Pane root = FXMLLoader.load(getClass().getResource("ressources/Menu.fxml")); // "ressources/Jouer_tour(1)lancer_des.fxml" primaryStage.setTitle("Shadow Hunters"); primaryStage.setScene(new Scene(root)); diff --git a/src/ihm/controller/PlateauController.java b/src/ihm/controller/PlateauController.java index b7ca076..f1da640 100644 --- a/src/ihm/controller/PlateauController.java +++ b/src/ihm/controller/PlateauController.java @@ -27,8 +27,6 @@ public class PlateauController implements Initializable { private List vboxJoueur = new ArrayList(); private List diff --git a/src/ihm/ressources/Plateau.fxml b/src/ihm/ressources/Plateau.fxml index 924e2fb..bec675d 100644 --- a/src/ihm/ressources/Plateau.fxml +++ b/src/ihm/ressources/Plateau.fxml @@ -19,8 +19,6 @@ - -