Ajout de commentaire et modification View_Clavardage
This commit is contained in:
parent
0b3a40c717
commit
8ed519838b
3 changed files with 117 additions and 120 deletions
|
@ -18,6 +18,9 @@ import javax.swing.JPanel;
|
|||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
/*
|
||||
* Classe represenyant la fenetre d'accueil pour la connexion d'un utilisateur.
|
||||
*/
|
||||
public class View_Accueil implements ActionListener{
|
||||
JFrame frame;
|
||||
JPanel panel;
|
||||
|
@ -25,78 +28,89 @@ public class View_Accueil implements ActionListener{
|
|||
JLabel Text;
|
||||
JButton Connexion;
|
||||
|
||||
/*
|
||||
* Constructeur d'une fenetre d'affichage pour la connexion d'un utilisateur.
|
||||
* Cette fenetre sera munie d'un bouton de connexion et d'une zone de saisie de pseudo.
|
||||
*/
|
||||
public View_Accueil () {
|
||||
//creer une instance JFrame
|
||||
frame = new JFrame("ChatApp-AL-NM");
|
||||
//sortir quand l’utilisateur ferme le frame
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
// fixer les dimensions de la fenetre
|
||||
frame.setSize(new Dimension(120, 40));
|
||||
|
||||
//Create and set up the panel.
|
||||
//Creer le JPanel
|
||||
panel = new JPanel(new GridLayout(3,1));
|
||||
|
||||
//Add the widgets.
|
||||
//Ajouter les elements
|
||||
this.addWidgets();
|
||||
|
||||
//Set the default button.
|
||||
frame.getRootPane().setDefaultButton(Connexion);
|
||||
|
||||
//Add the panel to the window.
|
||||
//Ajouter le panel a la window
|
||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
|
||||
//Display the window.
|
||||
//L'utilisateur ne pourra pas aggrandir la fenetre
|
||||
this.frame.setResizable(false);
|
||||
//Afficher la fenetre
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and add the widgets.
|
||||
* Creer et ajouter les outils de la fenetre
|
||||
*/
|
||||
private void addWidgets() {
|
||||
//Create widgets.
|
||||
this.pseudofield = new JTextField(2); // Zone d'insertion de texte
|
||||
// Créer Zone d'insertion de texte pour le pseudo
|
||||
this.pseudofield = new JTextField(2);
|
||||
// creation d'un label qui contiendra un txt au centre
|
||||
this.Text = new JLabel("Bonjour, Entrez un nom d'utilisateur!", SwingConstants.CENTER);
|
||||
//Ajout d'un bouton Connexion
|
||||
this.Connexion = new JButton("Connexion");
|
||||
|
||||
//Listen to events from the Convert button.
|
||||
//On associe au bouton Connexion des actions a realiser
|
||||
this.Connexion.addActionListener(this);
|
||||
|
||||
//Add the widgets to the container.
|
||||
// On ajouter les differents elements au panel
|
||||
panel.add(pseudofield);
|
||||
panel.add(Text);
|
||||
panel.add(Connexion);
|
||||
|
||||
//ajouter un effet de bord transparent au composant Jlabel
|
||||
Text.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Definir des traitements en réponse à un clic sur le bouton connexion
|
||||
* @param event Un clic sur le bouton connexion
|
||||
*/
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
// on recupere le texte entree dans la zone de saisie
|
||||
String pseudo = pseudofield.getText();
|
||||
// On crée un objet de type ChatApp
|
||||
ChatApp app = new ChatApp(pseudo, 3000) ;
|
||||
// on crée un thread qui va ecouter les connexions entrantes
|
||||
ExecutorService execUDP = Executors.newFixedThreadPool(1000);
|
||||
execUDP.submit(new RunnerEcouteUDP(app));
|
||||
Boolean connexion = false ;
|
||||
try {
|
||||
// on tente une connexion avec ce pseudo
|
||||
connexion = app.connexion();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// Dans les deux cas de figures (reussite ou echec) on affiche un pop-up pour expliquer la situation
|
||||
if(connexion) {
|
||||
// La connexion a reussi
|
||||
JOptionPane.showMessageDialog(frame, "Bonjour " + pseudo) ;
|
||||
frame.dispose();
|
||||
View_Courante fenetreCourante= new View_Courante(app);
|
||||
// on lance une nouvelle fenetre de type View_Menu
|
||||
View_Menu fenetreCourante= new View_Menu(app);
|
||||
}
|
||||
else {
|
||||
// La connexion a echoue, il est possible de rentrer un nouveau pseudo
|
||||
JOptionPane.showMessageDialog(frame, "Echec de Connexion , ce pseudo est deja pris !");
|
||||
}
|
||||
}
|
||||
|
||||
private static void createAndShowGUI() {
|
||||
//Make sure we have nice window decorations.
|
||||
// Etre certain d'avoir une joli fenetre
|
||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||
// On crée une fentre d'acceuil
|
||||
View_Accueil fenetre = new View_Accueil();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,103 +24,73 @@ import java.awt.Color;
|
|||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
|
||||
/*
|
||||
* Classe representant la fenetre pour chaque session de clavardage.
|
||||
*/
|
||||
public class View_Clavardage {
|
||||
JFrame frame ;
|
||||
ChatApp app;
|
||||
Utilisateur destination ;
|
||||
Utilisateur source;
|
||||
Utilisateur destination ; // Celui avec qui on va discuter
|
||||
Utilisateur source; //Nous
|
||||
WindowAdapter wa ;
|
||||
JPanel panel ;
|
||||
JTextArea textAreaAffichage ;
|
||||
|
||||
/*
|
||||
* Constructeur d'une fenetre de session de clavardage.
|
||||
* @param app Un objet de type ChatApp pour posseder toutes les informations de l'utilisateur
|
||||
* @param User2 L'utilisateur avec qui l'on souhaite discuter et passer en parametre sous forme de String
|
||||
*/
|
||||
public View_Clavardage(ChatApp app, String User2) {
|
||||
this.app = app ;
|
||||
this.frame = new JFrame("ChatApp-AL-NM");
|
||||
this.source = this.app.getMe();
|
||||
this.destination = Utilisateur.stringToUtilisateur(User2);
|
||||
this.frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // FERME TOUTE LES FENETRES ATTENTION
|
||||
this.frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
// fixer les dimensions de la fenetre
|
||||
this.frame.setSize(new Dimension(394, 344));
|
||||
this.frame.setResizable(false);
|
||||
|
||||
wa = new WindowAdapter(){
|
||||
public void windowClosing(WindowEvent e){
|
||||
int reponse = View_Courante.showConfirmDialog();
|
||||
int reponse = View_Menu.showConfirmDialog();
|
||||
if (reponse==0){
|
||||
frame.dispose();
|
||||
}
|
||||
}};
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{394, 0};
|
||||
gridBagLayout.rowHeights = new int[]{16, 220, 74, 0};
|
||||
gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
frame.getContentPane().setLayout(gridBagLayout);
|
||||
panel = new JPanel();
|
||||
JTextArea textAreaSaisie = new JTextArea(5,3);
|
||||
textAreaSaisie.setForeground(Color.LIGHT_GRAY);
|
||||
textAreaSaisie.setFont(new Font("Lucida Grande", Font.ITALIC, 11));
|
||||
textAreaSaisie.setText("Entrer du texte ici !!!");
|
||||
JScrollPane scrollPane = new JScrollPane(textAreaSaisie);
|
||||
JButton send = new JButton("Envoye");
|
||||
frame.getRootPane().setDefaultButton(send);
|
||||
send.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
//UTILISER TCPENVOI
|
||||
textAreaSaisie.setText("");
|
||||
}});
|
||||
JButton reset = new JButton("Vider");
|
||||
reset.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
textAreaSaisie.setText("");
|
||||
}});
|
||||
JLabel titre = new JLabel("Chat avec "+ this.destination.getPseudo(),SwingConstants.CENTER);
|
||||
GridBagConstraints gbc_titre = new GridBagConstraints();
|
||||
gbc_titre.anchor = GridBagConstraints.NORTH;
|
||||
gbc_titre.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_titre.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_titre.gridx = 0;
|
||||
gbc_titre.gridy = 0;
|
||||
frame.getContentPane().add(titre, gbc_titre);
|
||||
JTextArea textAreaAffichage = new JTextArea(10,5);
|
||||
textAreaAffichage.setText("");
|
||||
JScrollPane scrollPaneAffichage = new JScrollPane(textAreaAffichage);
|
||||
textAreaAffichage.setEditable(false);
|
||||
GridBagConstraints gbc_textAreaAffichage = new GridBagConstraints();
|
||||
gbc_textAreaAffichage.fill = GridBagConstraints.BOTH;
|
||||
gbc_textAreaAffichage.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_textAreaAffichage.gridx = 0;
|
||||
gbc_textAreaAffichage.gridy = 1;
|
||||
frame.getContentPane().add(scrollPaneAffichage, gbc_textAreaAffichage);
|
||||
panel.add(BorderLayout.CENTER, scrollPane);
|
||||
//panel.add(scrollPane);
|
||||
panel.add(BorderLayout.SOUTH,send);
|
||||
panel.add(BorderLayout.SOUTH,reset);
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||
//Add the panel to the window.
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.anchor = GridBagConstraints.NORTH;
|
||||
gbc_panel.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 2;
|
||||
frame.getContentPane().add(panel, gbc_panel);
|
||||
//addWidgets();
|
||||
addWidgets();
|
||||
frame.addWindowListener( wa ) ;
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creer et ajouter les outils de la fenetre
|
||||
*/
|
||||
private void addWidgets() {
|
||||
panel = new JPanel();
|
||||
JTextArea textAreaSaisie = new JTextArea(5,5);
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{394, 0};
|
||||
gridBagLayout.rowHeights = new int[]{16, 220, 74, 0};
|
||||
gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
this.frame.getContentPane().setLayout(gridBagLayout);
|
||||
this.panel = new JPanel();
|
||||
// Zone pour ecrire de nouveau message
|
||||
JTextArea textAreaSaisie = new JTextArea(5,3);
|
||||
textAreaSaisie.setLineWrap(true);
|
||||
textAreaSaisie.setForeground(Color.LIGHT_GRAY);
|
||||
textAreaSaisie.setFont(new Font("Lucida Grande", Font.ITALIC, 11));
|
||||
textAreaSaisie.setText("Entrer du texte ici !!!");
|
||||
JScrollPane scrollPane = new JScrollPane(textAreaSaisie);
|
||||
// Creation d'un bouton envoye
|
||||
JButton send = new JButton("Envoye");
|
||||
frame.getRootPane().setDefaultButton(send);
|
||||
send.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
//UTILISER TCPENVOI
|
||||
String AEnvoyer = textAreaSaisie.getText();
|
||||
textAreaAffichage.append(AEnvoyer);
|
||||
textAreaSaisie.setText("");
|
||||
}});
|
||||
// Creation d'un bouton vider la zone de saisie de texte
|
||||
JButton reset = new JButton("Vider");
|
||||
reset.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
|
@ -134,16 +104,19 @@ public class View_Clavardage {
|
|||
gbc_titre.gridx = 0;
|
||||
gbc_titre.gridy = 0;
|
||||
frame.getContentPane().add(titre, gbc_titre);
|
||||
JTextArea textAreaAffichage = new JTextArea(10,5);
|
||||
textAreaAffichage.setEditable(false);
|
||||
// Zone d'affichage de l'historique
|
||||
this.textAreaAffichage = new JTextArea(10,5);
|
||||
textAreaAffichage.setLineWrap(true);
|
||||
this.textAreaAffichage.setText("");
|
||||
JScrollPane scrollPaneAffichage = new JScrollPane(this.textAreaAffichage);
|
||||
this.textAreaAffichage.setEditable(false); // il sert juste a afficher
|
||||
GridBagConstraints gbc_textAreaAffichage = new GridBagConstraints();
|
||||
gbc_textAreaAffichage.fill = GridBagConstraints.BOTH;
|
||||
gbc_textAreaAffichage.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_textAreaAffichage.gridx = 0;
|
||||
gbc_textAreaAffichage.gridy = 1;
|
||||
frame.getContentPane().add(textAreaAffichage, gbc_textAreaAffichage);
|
||||
frame.getContentPane().add(scrollPaneAffichage, gbc_textAreaAffichage);
|
||||
panel.add(BorderLayout.CENTER, scrollPane);
|
||||
//panel.add(scrollPane);
|
||||
panel.add(BorderLayout.SOUTH,send);
|
||||
panel.add(BorderLayout.SOUTH,reset);
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||
|
@ -154,7 +127,6 @@ public class View_Clavardage {
|
|||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 2;
|
||||
frame.getContentPane().add(panel, gbc_panel);
|
||||
|
||||
/*
|
||||
*
|
||||
*JTextArea textAreaAffichage = new JTextArea(10,5);
|
||||
|
|
|
@ -35,9 +35,13 @@ import javax.swing.SwingConstants;
|
|||
|
||||
import java.awt.Font;
|
||||
import java.awt.Color;
|
||||
import java.awt.ComponentOrientation;
|
||||
import java.awt.SystemColor;
|
||||
|
||||
public class View_Courante {
|
||||
/*
|
||||
* Classe representant la fenetre de menu. Lance apres la connexion d'un utilisateur
|
||||
*/
|
||||
public class View_Menu {
|
||||
JFrame frame;
|
||||
JPanel panel;
|
||||
JMenuBar menu;
|
||||
|
@ -46,19 +50,25 @@ public class View_Courante {
|
|||
JLabel Txt;
|
||||
WindowAdapter wa ;
|
||||
|
||||
public View_Courante(ChatApp app) {
|
||||
/*
|
||||
* Constructeur d'une fenetre de menu apres la connexion d'un utilisateur.
|
||||
* @param app Un objet de type ChatApp pour posseder toutes les informations de l'utilisateur
|
||||
*/
|
||||
public View_Menu(ChatApp app) {
|
||||
this.app = app ;
|
||||
//creer une instance JFrame
|
||||
frame = new JFrame("ChatApp-AL-NM");
|
||||
//sortir quand l’utilisateur ferme le frame
|
||||
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
// fixer les dimensions de la fenetre
|
||||
frame.setSize(new Dimension(394, 344));
|
||||
// Lorsque l'utilisateur souhaite quitter la fenetre on affiche un pop-up pour verifier son choix
|
||||
wa = new WindowAdapter(){
|
||||
public void windowClosing(WindowEvent e){
|
||||
int reponse = showConfirmDialog();
|
||||
if (reponse==0){
|
||||
try {
|
||||
// on deconnecte l'app avant de quitter
|
||||
// Tout les utilisateurs sont donc prevenus du depart
|
||||
app.deconnexion();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
|
@ -67,23 +77,23 @@ public class View_Courante {
|
|||
}
|
||||
}};
|
||||
frame.addWindowListener( wa ) ;
|
||||
// Menu pour les differentes actions réalisables
|
||||
menu = new JMenuBar();
|
||||
|
||||
//Create and set up the panel.
|
||||
//Creation d'un JPanel
|
||||
panel = new JPanel(new GridLayout(3,1));
|
||||
panel.setForeground(SystemColor.menuText);
|
||||
|
||||
//Add the widgets.
|
||||
// Ajouter tout les elements a la fenetre
|
||||
this.addWidgets();
|
||||
|
||||
//Add the panel to the window.
|
||||
// ajouter le panel a la fenetre
|
||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
|
||||
//Display the window.
|
||||
// Afficher la fenetre
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Methode static creant un pop-up demandant a l'utilisateur si il souhaite vraiment quitter.
|
||||
*/
|
||||
static int showConfirmDialog(){
|
||||
return JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
|
@ -92,15 +102,17 @@ public class View_Courante {
|
|||
JOptionPane.YES_NO_OPTION);
|
||||
}
|
||||
/**
|
||||
* Create and add the widgets.
|
||||
* Creer et ajouter les outils de la fenetre
|
||||
*/
|
||||
private void addWidgets() {
|
||||
// On ajoute une jolie icone
|
||||
jlabel = new JLabel(new ImageIcon("/Users/auriane/Desktop/ChatApp-AL-NM/Implementation/src/images/Logo.png"), JLabel.CENTER);
|
||||
|
||||
Txt = new JLabel("Menu principal de " + app.getMe().getPseudo());
|
||||
Txt = new JLabel("Menu principal de " + app.getMe().getPseudo());
|
||||
Txt.setFont(new Font("Tamil MN", Font.PLAIN, 30));
|
||||
Txt.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
//On cree une item Actions que l'on ajoutera a la bar de menu
|
||||
JMenu Actions = new JMenu("Actions");
|
||||
Actions.setForeground(Color.WHITE);
|
||||
Actions.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
@ -109,18 +121,17 @@ public class View_Courante {
|
|||
JMenuItem session = new JMenuItem("Session de Clavardage");
|
||||
JMenuItem pseudo = new JMenuItem("Modifier Pseudo");
|
||||
JMenuItem deconnexion = new JMenuItem("Deconnexion");
|
||||
Actions.add(actifs);
|
||||
Actions.add(session);
|
||||
Actions.add(pseudo);
|
||||
Actions.add(deconnexion);
|
||||
|
||||
|
||||
menu.add(Actions);
|
||||
|
||||
|
||||
panel.add(BorderLayout.NORTH , menu);
|
||||
panel.add(BorderLayout.CENTER, jlabel);
|
||||
panel.add(BorderLayout.SOUTH , Txt );
|
||||
// Ajouter les sous items a actions
|
||||
Actions.add(actifs);
|
||||
Actions.add(session);
|
||||
Actions.add(pseudo);
|
||||
Actions.add(deconnexion);
|
||||
// On ajoute l'item Action dans la bar de menu
|
||||
menu.add(Actions);
|
||||
// On ajouter les differents elements au panel
|
||||
panel.add(BorderLayout.NORTH , menu);
|
||||
panel.add(BorderLayout.CENTER, jlabel);
|
||||
panel.add(BorderLayout.SOUTH , Txt );
|
||||
|
||||
//******************************************************************************************************************
|
||||
//**************************************** Actions lorsque l'on clique sur actifs **********************************
|
||||
|
@ -142,7 +153,7 @@ public class View_Courante {
|
|||
home.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
frame.dispose();
|
||||
new View_Courante(app);
|
||||
new View_Menu(app);
|
||||
} });
|
||||
textArea.setEditable(false);
|
||||
frame.getContentPane().removeAll();
|
||||
|
@ -160,7 +171,7 @@ public class View_Courante {
|
|||
home.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
frame.dispose();
|
||||
new View_Courante(app);
|
||||
new View_Menu(app);
|
||||
} });
|
||||
String utilisateurs = app.getActifUsers().afficherListeUtilisateurs();
|
||||
Vector<String> vector = new Vector<String>();
|
||||
|
@ -195,7 +206,7 @@ public class View_Courante {
|
|||
home.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
frame.dispose();
|
||||
new View_Courante(app);
|
||||
new View_Menu(app);
|
||||
} });
|
||||
//Ajout d'un bouton Valider
|
||||
JButton Valider = new JButton("Valider");
|
||||
|
@ -209,7 +220,7 @@ public class View_Courante {
|
|||
if(resultat) {
|
||||
JOptionPane.showMessageDialog(frame, "Modification pseudo Reussi");
|
||||
frame.dispose();
|
||||
new View_Courante(app);
|
||||
new View_Menu(app);
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(frame, "Echec Modification pseudo ");
|
Loading…
Reference in a new issue