1 Commits

Author SHA1 Message Date
Val Jenson 08ce0e73d8 test d'une vue 2025-10-16 10:14:15 +02:00
10 changed files with 31 additions and 157 deletions
BIN
View File
Binary file not shown.
Binary file not shown.
-9
View File
@@ -1,9 +0,0 @@
-- Table principale : les rappels
CREATE TABLE rappel (
id INT AUTO_INCREMENT PRIMARY KEY,
titre VARCHAR(50) NOT NULL,
contenu TEXT,
theme VARCHAR(30),
rang INT
);
View File
@@ -1,16 +0,0 @@
package fr.iutfbleau.papillon.vue;
import javax.swing.*;
import java.awt.*;
public class VuePrincipale extends JFrame {
// composants publics “contrôlés” par le contrôleur
public final JTextField champTitre = new JTextField(20);
public final JTextArea champContenu = new JTextArea(4, 20);
public final JTextArea zoneAffiche = new JTextArea(12, 26);
public final JButton boutonAjouter = new JButton("Ajouter");
public final JButton boutonLister = new JButton("Lister");
public VuePrincipale() {
}
}
@@ -1,59 +0,0 @@
package fr.iutfbleau.papillon.controller;
import fr.iutfbleau.papillon.model.BaseDeDonnees;
import fr.iutfbleau.papillon.model.Rappel;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class GestionRappel {
public void ajouter(Rappel r) throws SQLException {
String sql = "INSERT INTO rappel (titre, contenu, theme, rang) VALUES (?, ?, ?, ?)";
Connection cnx = BaseDeDonnees.getConnexion();
PreparedStatement pst = cnx.prepareStatement(sql);
pst.setString(1, r.getTitre());
pst.setString(2, r.getContenu());
pst.setString(3, r.getTheme());
pst.setInt(4, r.getRang());
pst.executeUpdate();
pst.close();
}
public List<String> lister() throws SQLException {
String sql = "SELECT id, titre, theme, rang FROM rappel ORDER BY id DESC";
List<String> res = new ArrayList<>();
Connection cnx = BaseDeDonnees.getConnexion();
PreparedStatement pst = cnx.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
res.add(rs.getInt("id") + " | " + rs.getString("titre") + " | " + rs.getString("theme") + " | " + rs.getInt("rang"));
}
rs.close();
pst.close();
return res;
}
public void supprimerParId(int id) throws SQLException {
String sql = "DELETE FROM rappel WHERE id = ?";
Connection cnx = BaseDeDonnees.getConnexion();
PreparedStatement pst = cnx.prepareStatement(sql);
pst.setInt(1, id);
pst.executeUpdate();
pst.close();
}
public void modifierParId(int id, Rappel r) throws SQLException {
String sql = "UPDATE rappel SET titre = ?, contenu = ?, theme = ?, rang = ? WHERE id = ?";
Connection cnx = BaseDeDonnees.getConnexion();
PreparedStatement pst = cnx.prepareStatement(sql);
pst.setString(1, r.getTitre());
pst.setString(2, r.getContenu());
pst.setString(3, r.getTheme());
pst.setInt(4, r.getRang());
pst.setInt(5, id);
pst.executeUpdate();
pst.close();
}
}
@@ -1,38 +0,0 @@
package fr.iutfbleau.papillon.model;
import org.mariadb.jdbc.MariaDbDataSource;
import java.sql.Connection;
import java.sql.SQLException;
public class BaseDeDonnees {
private static Connection connexion;
public static Connection getConnexion() {
if (connexion == null) {
try {
MariaDbDataSource dataSource = new MariaDbDataSource();
dataSource.setUrl("jdbc:mariadb://localhost:3307/papillon");
dataSource.setUser("root");
dataSource.setPassword("mdp");
connexion = dataSource.getConnection();
System.out.println(" Connexion réussie !");
} catch (SQLException e) {
e.printStackTrace();
}
}
return connexion;
}
public static void fermer() {
try {
if (connexion != null && !connexion.isClosed()) {
connexion.close();
System.out.println(" Connexion fermée.");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
@@ -1,35 +0,0 @@
package fr.iutfbleau.papillon.model;
public class Rappel {
private int id;
private String titre;
private String contenu;
private LocalDateTime date;
public Rappel(int id, String titre, String contenu, LocalDateTime date) {
this.id = id;
this.titre = titre;
this.contenu = contenu;
this.date = date;
}
public Rappel(String titre, String contenu, String theme, int rang){
this(0,titre,contenu,theme,rang);
}
public int getId(){
return id;
}
public String getTitre(){
return titre;
}
public String getContenu(){
return contenu;
}
public String getTheme(){
return theme;
}
public int getRang(){
return rang;
}
}
Binary file not shown.
@@ -0,0 +1,31 @@
/*package fr.iutfbleau.papillon.vue;*/
import javax.swing.*;
import java.awt.*;
public class VuePrincipale extends JFrame {
// composants publics “contrôlés” par le contrôleur
public static JTextField champTitre = new JTextField(20);
public static JTextArea champContenu = new JTextArea(4, 20);
public static JTextArea zoneAffiche = new JTextArea(12, 26);
public static JButton boutonAjouter = new JButton("Ajouter");
public static JButton boutonLister = new JButton("Lister");
public VuePrincipale() {
super("Rappel");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 300);
setLayout(new GridLayout(5, 1));
add(champTitre);
add(champContenu);
add(zoneAffiche);
add(boutonAjouter);
add(boutonLister);
setVisible(true);
}
public static void main(String[] args) {
new VuePrincipale();
}
}