Files
Projet-Dev/linea/LineaAppli.java

110 lines
2.9 KiB
Java
Raw Normal View History

2026-02-10 16:39:21 +01:00
package linea;
2026-03-25 20:54:24 +01:00
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
2026-02-10 16:39:21 +01:00
public class LineaAppli {
2026-03-25 20:54:24 +01:00
private static String choisirPseudo(DatabaseConnection db, String message, int messageType) {
List<String> pseudos = db.getPseudos();
if (pseudos.isEmpty()) {
JOptionPane.showMessageDialog(null, "Aucun compte disponible.");
return null;
}
return (String) JOptionPane.showInputDialog(
null,
message,
"Comptes",
messageType,
null,
pseudos.toArray(String[]::new),
pseudos.get(0)
);
}
private static Integer menuComptes(DatabaseConnection db) {
while (true) {
Object[] options = {"Sélectionner", "Créer", "Supprimer", "Retour"};
int choix = JOptionPane.showOptionDialog(
null,
"Gestion des comptes :",
"Comptes",
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]
);
if (choix == JOptionPane.CLOSED_OPTION || choix == 3) return null;
switch (choix) {
case 0 -> {
String pseudo = choisirPseudo(db, "Sélectionnez un compte :", JOptionPane.QUESTION_MESSAGE);
if (pseudo != null) return db.getIdParPseudo(pseudo);
}
case 1 -> {
String pseudo = JOptionPane.showInputDialog(null, "Nouveau pseudo :");
if (pseudo == null || pseudo.trim().isEmpty()) continue;
pseudo = pseudo.trim();
int id = db.getIdParPseudo(pseudo);
return id > 0 ? id : db.creerCompte(pseudo);
}
case 2 -> {
String pseudo = choisirPseudo(db, "Sélectionnez le compte à supprimer :", JOptionPane.WARNING_MESSAGE);
if (pseudo == null) continue;
int confirm = JOptionPane.showConfirmDialog(
null,
"Supprimer le compte \"" + pseudo + "\" et toute sa progression ?",
"Confirmation",
JOptionPane.YES_NO_OPTION
);
if (confirm == JOptionPane.YES_OPTION) {
int id = db.getIdParPseudo(pseudo);
if (id > 0) db.supprimerCompte(id);
}
}
}
}
}
2026-02-10 16:39:21 +01:00
//-------------------------------------------------------------------------
// Classe de base de l'application, rien à modifier ici
//-------------------------------------------------------------------------
public static void main(String[] arg) {
2026-03-25 20:54:24 +01:00
UIManager.put("OptionPane.cancelButtonText", "Retour");
DatabaseConnection db = new DatabaseConnection();
db.connect();
db.createTables();
while (true) {
Object[] options = {"Comptes", "Sans compte", "Quitter"};
int choix = JOptionPane.showOptionDialog(null,
"Choisissez une action :",
"Menu", JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if (choix == JOptionPane.CLOSED_OPTION || choix == 2) {
return;
}
2026-02-10 16:39:21 +01:00
2026-03-25 20:54:24 +01:00
switch (choix) {
case 1 -> {
new Jeu(db, -1).demarrer();
return;
}
case 0 -> {
Integer idCompte = menuComptes(db);
if (idCompte != null) {
new Jeu(db, idCompte).demarrer();
return;
}
}
}
}
2026-02-10 16:39:21 +01:00
}
}