fixed Inter
This commit is contained in:
parent
bb30cbbe2e
commit
82ce381418
|
|
@ -23,8 +23,9 @@ import javax.swing.JTextArea;
|
|||
import javax.swing.SwingConstants;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class inter extends JFrame {
|
||||
public class Inter extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final int WINDOW_WIDTH = 600;
|
||||
|
|
@ -39,7 +40,8 @@ public class inter extends JFrame {
|
|||
private JButton entreeButton;
|
||||
|
||||
private ListeAvis listeAvis;
|
||||
private Dictionnaire dico;
|
||||
private String cheminBigCsv;
|
||||
private String cheminDictionnaire;
|
||||
|
||||
// Cache des données
|
||||
// private final Map<Integer, List<String>> commentairesFilms = new HashMap<>();
|
||||
|
|
@ -52,7 +54,7 @@ public class inter extends JFrame {
|
|||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(() -> {
|
||||
try {
|
||||
inter frame = new inter();
|
||||
Inter frame = new Inter();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -63,9 +65,11 @@ public class inter extends JFrame {
|
|||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public inter() {
|
||||
dico = new Dictionnaire("C:\\Users\\Qpelu\\Downloads\\dictionnaire.csv");
|
||||
listeAvis = new ListeAvis("C:\\\\Users\\\\Qpelu\\\\Downloads\\\\big.csv\\");
|
||||
public Inter() {
|
||||
// Les chemins seront définis via l'interface utilisateur
|
||||
cheminBigCsv = "";
|
||||
cheminDictionnaire = "";
|
||||
|
||||
initialiserDictionnaireSentiments();
|
||||
initialiserInterface();
|
||||
}
|
||||
|
|
@ -99,7 +103,100 @@ public class inter extends JFrame {
|
|||
panel.add(buttonPanel, BorderLayout.CENTER);
|
||||
|
||||
// Action du bouton initial
|
||||
entreeButton.addActionListener(e -> afficherFilms());
|
||||
entreeButton.addActionListener(e -> afficherEcranChemins());
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche l'écran de saisie des chemins d'accès aux fichiers
|
||||
*/
|
||||
private void afficherEcranChemins() {
|
||||
panel.removeAll();
|
||||
panel.setLayout(new BorderLayout(MARGIN, MARGIN));
|
||||
panel.setBorder(new EmptyBorder(MARGIN, MARGIN, MARGIN, MARGIN));
|
||||
|
||||
// Titre
|
||||
JLabel titreLabel = new JLabel("Veuillez saisir les chemins d'accès");
|
||||
titreLabel.setFont(TITLE_FONT);
|
||||
titreLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(titreLabel, BorderLayout.NORTH);
|
||||
|
||||
// Panel central pour les champs de saisie
|
||||
JPanel formPanel = new JPanel();
|
||||
formPanel.setLayout(new GridLayout(4, 1, MARGIN, MARGIN));
|
||||
|
||||
// Champ pour big.csv
|
||||
JPanel bigCsvPanel = new JPanel(new BorderLayout(MARGIN, 0));
|
||||
JLabel bigCsvLabel = new JLabel("Chemin d'accès vers big.csv :");
|
||||
JTextField bigCsvField = new JTextField();
|
||||
bigCsvField.setText(cheminBigCsv);
|
||||
bigCsvPanel.add(bigCsvLabel, BorderLayout.NORTH);
|
||||
bigCsvPanel.add(bigCsvField, BorderLayout.CENTER);
|
||||
formPanel.add(bigCsvPanel);
|
||||
|
||||
// Champ pour dictionnaire.csv
|
||||
JPanel dicoPanel = new JPanel(new BorderLayout(MARGIN, 0));
|
||||
JLabel dicoLabel = new JLabel("Chemin d'accès pour créer/charger dictionnaire.csv :");
|
||||
JTextField dicoField = new JTextField();
|
||||
dicoField.setText(cheminDictionnaire);
|
||||
dicoPanel.add(dicoLabel, BorderLayout.NORTH);
|
||||
dicoPanel.add(dicoField, BorderLayout.CENTER);
|
||||
formPanel.add(dicoPanel);
|
||||
|
||||
// Bouton de validation
|
||||
JPanel validationPanel = new JPanel(new BorderLayout());
|
||||
JButton validerButton = new JButton("Valider");
|
||||
validationPanel.add(validerButton, BorderLayout.CENTER);
|
||||
formPanel.add(validationPanel);
|
||||
|
||||
panel.add(formPanel, BorderLayout.CENTER);
|
||||
|
||||
// Action du bouton de validation
|
||||
validerButton.addActionListener(e -> {
|
||||
// Récupérer et valider les chemins
|
||||
String nouveauCheminBig = bigCsvField.getText().trim();
|
||||
String nouveauCheminDico = dicoField.getText().trim();
|
||||
|
||||
if (nouveauCheminBig.isEmpty() || nouveauCheminDico.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(panel,
|
||||
"Veuillez remplir les deux champs de chemin d'accès.",
|
||||
"Erreur",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
// Mettre à jour les chemins
|
||||
cheminBigCsv = nouveauCheminBig;
|
||||
cheminDictionnaire = nouveauCheminDico;
|
||||
|
||||
// Initialiser les données avec les nouveaux chemins
|
||||
try {
|
||||
listeAvis = new ListeAvis(cheminBigCsv);
|
||||
|
||||
// Créer ou charger le dictionnaire
|
||||
Dictionnaire dictionnaire = new Dictionnaire();
|
||||
|
||||
// Apprentissage du dictionnaire à partir des avis
|
||||
dictionnaire.apprentissageSentiment(listeAvis.getListeAvis());
|
||||
|
||||
// Sauvegarder le dictionnaire
|
||||
dictionnaire.sauvegarderDictionnaireCSV(cheminDictionnaire);
|
||||
|
||||
// Passer à l'écran des films
|
||||
afficherFilms();
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(panel,
|
||||
"Erreur lors du chargement des fichiers : " + ex.getMessage(),
|
||||
"Erreur",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
// Bouton retour
|
||||
JButton retourButton = new JButton("Retour");
|
||||
retourButton.addActionListener(e -> afficherEcranInitial());
|
||||
panel.add(retourButton, BorderLayout.SOUTH);
|
||||
|
||||
rafraichirPanel();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -177,7 +274,7 @@ public class inter extends JFrame {
|
|||
|
||||
// Bouton retour
|
||||
JButton retourBas = new JButton("Retour");
|
||||
retourBas.addActionListener(e -> afficherEcranInitial());
|
||||
retourBas.addActionListener(e -> afficherEcranChemins());
|
||||
panel.add(retourBas, BorderLayout.SOUTH);
|
||||
|
||||
rafraichirPanel();
|
||||
|
|
@ -201,12 +298,11 @@ public class inter extends JFrame {
|
|||
|
||||
private int calculerNoteMoyenne(int filmNumber) {
|
||||
int totalNotes= 0;
|
||||
Dictionnaire dico=new Dictionnaire("C:\\Users\\Qpelu\\Downloads\\dictionnaire.csv");
|
||||
Dictionnaire dico=new Dictionnaire(cheminDictionnaire);
|
||||
Avis av = new Avis();
|
||||
|
||||
totalNotes += av.Analyse(listeAvis.getCommentairesParFilm(filmNumber), dico);
|
||||
System.out.println(totalNotes);
|
||||
|
||||
System.out.println(totalNotes);
|
||||
|
||||
return totalNotes;
|
||||
}
|
||||
|
|
@ -239,8 +335,6 @@ public class inter extends JFrame {
|
|||
JPanel centralPanel = new JPanel();
|
||||
centralPanel.setLayout(new GridLayout(1, 2, MARGIN, 0));
|
||||
|
||||
|
||||
|
||||
List<String> commentaires = listeAvis.getCommentairesParFilm(filmNumber);
|
||||
|
||||
// Panel pour la note et les commentaires affichés
|
||||
|
|
@ -395,17 +489,10 @@ public class inter extends JFrame {
|
|||
*/
|
||||
private void ajouterCommentaire(int filmNumber, String c) {
|
||||
// Récupérer la liste des commentaires
|
||||
|
||||
Avis av =new Avis(0,c,"none",filmNumber);
|
||||
Dictionnaire dico = new Dictionnaire(cheminDictionnaire);
|
||||
Avis av =new Avis();
|
||||
List<String> commentaires = listeAvis.getCommentairesParFilm(filmNumber);
|
||||
commentaires.add(c);
|
||||
listeAvis.add(new Avis(filmNumber, "url", c, 0));
|
||||
|
||||
List<String> com = new ArrayList<>();
|
||||
commentaires.add("c");
|
||||
int note = av.Analyse(com, dico);
|
||||
|
||||
|
||||
|
||||
// Calculer la nouvelle note moyenne
|
||||
int noteMoyenne = av.Analyse(commentaires, dico);
|
||||
|
|
@ -416,7 +503,7 @@ public class inter extends JFrame {
|
|||
|
||||
// Afficher un message de confirmation
|
||||
JOptionPane.showMessageDialog(panel,
|
||||
"Commentaire ajouté avec succès !\nNote moyenne du film : " + note + "/5",
|
||||
"Commentaire ajouté avec succès !\nNote moyenne du film : " + noteMoyenne + "/5",
|
||||
"Succès",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
Loading…
Reference in New Issue