Page de connexion et d'acceuil
このコミットが含まれているのは:
コミット
e7c4a39a75
7個のファイルの変更、270行の追加、71行の削除
|
@ -64,13 +64,14 @@ public class ChatApp {
|
|||
* Envoie en broadcast ses informations utilisateurs et son nouveau pseudo
|
||||
*
|
||||
* @param nouveau correspond au nouveau pseudo
|
||||
* @return False si modiferPseudo a echoue, True sinon
|
||||
*/
|
||||
public void modifierPseudo(String nouveau) throws IOException {
|
||||
public Boolean modifierPseudo(String nouveau) throws IOException {
|
||||
// Message que l'on envoie à tous les utilisateurs actifs
|
||||
String broadcastMessage = "Demande Modification Pseudo\n" + this.getMe().toString() + "\n" + nouveau + "\n";
|
||||
UDPEchange.EnvoiBroadcast(broadcastMessage);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
Thread.sleep(2000);
|
||||
/* L'utilisateur doit attendre la reponse de tous les utilisateurs connectes
|
||||
* pour savoir si son pseudo est accepte
|
||||
*/
|
||||
|
@ -87,11 +88,12 @@ public class ChatApp {
|
|||
this.getMe().setPseudo(nouveau);
|
||||
System.out.println("Changement pseudo accepte, nouvelle liste des utilisateurs actifs:");
|
||||
this.getActifUsers().afficherListeUtilisateurs();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Connexion echoue");
|
||||
System.exit(1) ; // A MODIFIER NORMALEMENT ON LUI DEMANDE DE CHOISIR UN NV MDP
|
||||
System.out.println("Echec Modification pseudo");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,24 +101,26 @@ public class ChatApp {
|
|||
/**
|
||||
* Methode appelee lors de la connexion d'un nouvel utilisateur.
|
||||
* Il va prevenir les utilisateurs du reseau de son arrivee.
|
||||
*
|
||||
* @return False si Connexion a echoue, True sinon
|
||||
*/
|
||||
public void connexion() throws IOException {
|
||||
public Boolean connexion() throws IOException {
|
||||
// Message que l'on envoie à tous les utilisateurs actifs
|
||||
String broadcastMessage = "Connexion\n" + this.getMe().toString() ;
|
||||
UDPEchange.EnvoiBroadcast(broadcastMessage);
|
||||
try {
|
||||
Thread.sleep(1000); // L'utilisateur doit attendre la reponse de tous les utilisateurs connectes
|
||||
Thread.sleep(2000); // L'utilisateur doit attendre la reponse de tous les utilisateurs connectes
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (UDPEchange.getConnecte()) {
|
||||
System.out.println("Connexion reussie");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Connexion echoue");
|
||||
System.exit(1) ; // A MODIFIER NORMALEMENT ON LUI DEMANDE DE CHOISIR UN NV MDP
|
||||
UDPEchange.setConnecte(true);
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,11 +99,14 @@ public class ListUtilisateurs {
|
|||
* Méthode affichant la liste des utilisateurs actifs
|
||||
*
|
||||
*/
|
||||
public void afficherListeUtilisateurs() {
|
||||
public String afficherListeUtilisateurs() {
|
||||
System.out.println ("Liste des utilisateurs actifs : ");
|
||||
String Utilisateur = "" ;
|
||||
for(Utilisateur elem: this.actifUsers)
|
||||
{
|
||||
System.out.println (elem.toString());
|
||||
Utilisateur += (elem + "\n");
|
||||
}
|
||||
return Utilisateur;
|
||||
}
|
||||
}
|
||||
|
|
49
Implementation/src/Modification_Pseudo.java
ノーマルファイル
49
Implementation/src/Modification_Pseudo.java
ノーマルファイル
|
@ -0,0 +1,49 @@
|
|||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
public class Modification_Pseudo extends JPanel{
|
||||
ChatApp app;
|
||||
public Modification_Pseudo(String name, ChatApp app) {
|
||||
this.app = app ;
|
||||
JLabel Text = new JLabel("Entrez un nouveau nom d'utilisateur!", SwingConstants.CENTER);
|
||||
JTextField pseudofield = new JTextField(2); // Zone d'insertion de texte
|
||||
JButton home = new JButton(new ImageIcon("/Users/auriane/Desktop/ChatApp-AL-NM/Implementation/src/images/Home.png"));
|
||||
//Ajout d'un bouton Valider
|
||||
JButton Valider = new JButton("Valider");
|
||||
this.getRootPane().setDefaultButton(Valider);
|
||||
//Listen to events from the Valider button.
|
||||
Valider.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String nouveau = pseudofield.getText();
|
||||
try {
|
||||
Boolean resultat = app.modifierPseudo(nouveau);
|
||||
if(resultat) {
|
||||
|
||||
}
|
||||
else {
|
||||
//JOptionPane.showMessageDialog(this, "Echec de modification de pseudo, " + nouveau +" deja pris", JOptionPane.WARNING_MESSAGE);
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.add(home);
|
||||
this.add(Text);
|
||||
this.add(BorderLayout.CENTER,pseudofield);
|
||||
this.add(BorderLayout.SOUTH,Valider);
|
||||
|
||||
}
|
||||
}
|
|
@ -79,14 +79,20 @@ public class View_Accueil implements ActionListener{
|
|||
ChatApp app = new ChatApp(pseudo, 3000) ;
|
||||
ExecutorService execUDP = Executors.newFixedThreadPool(1000);
|
||||
execUDP.submit(new RunnerEcouteUDP(app));
|
||||
Boolean connexion = false ;
|
||||
try {
|
||||
app.connexion();
|
||||
connexion = app.connexion();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//JOptionPane.showMessageDialog(frame, "Bonjour " + pseudo);
|
||||
frame.dispose();
|
||||
View_Courante fenetreCourante= new View_Courante(app);
|
||||
if(connexion) {
|
||||
JOptionPane.showMessageDialog(frame, "Bonjour " + pseudo) ;
|
||||
frame.dispose();
|
||||
View_Courante fenetreCourante= new View_Courante(app);
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(frame, "Echec de Connexion , ce pseudo est deja pris !");
|
||||
}
|
||||
}
|
||||
private static void createAndShowGUI() {
|
||||
//Make sure we have nice window decorations.
|
||||
|
|
53
Implementation/src/View_Clavardage.java
ノーマルファイル
53
Implementation/src/View_Clavardage.java
ノーマルファイル
|
@ -0,0 +1,53 @@
|
|||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class View_Clavardage {
|
||||
JFrame frame ;
|
||||
ChatApp app;
|
||||
Utilisateur destination ;
|
||||
Utilisateur source;
|
||||
WindowAdapter wa ;
|
||||
JPanel panel ;
|
||||
public View_Clavardage(ChatApp app, String User2) {
|
||||
this.app = app ;
|
||||
this.frame = new JFrame("ChatApp-AL-NM");
|
||||
this.destination = this.app.getMe();
|
||||
this.source = Utilisateur.stringToUtilisateur(User2);
|
||||
this.frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // FERME TOUTE LES FENETRES ATTENTION
|
||||
// fixer les dimensions de la fenetre
|
||||
this.frame.setSize(new Dimension(394, 344));
|
||||
wa = new WindowAdapter(){
|
||||
public void windowClosing(WindowEvent e){
|
||||
int reponse = View_Courante.showConfirmDialog();
|
||||
if (reponse==0){
|
||||
try {
|
||||
app.deconnexion();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
frame.dispose();
|
||||
}
|
||||
}};
|
||||
panel = new JPanel();
|
||||
frame.addWindowListener( wa ) ;
|
||||
//Add the widgets.
|
||||
this.addWidgets();
|
||||
|
||||
//Add the panel to the window.
|
||||
frame.getContentPane().add(this.panel, BorderLayout.CENTER);
|
||||
|
||||
//Display the window.
|
||||
//frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
private void addWidgets() {}
|
||||
|
||||
|
||||
}
|
|
@ -9,6 +9,7 @@ import java.awt.event.WindowEvent;
|
|||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
@ -17,6 +18,7 @@ import javax.swing.AbstractAction;
|
|||
import javax.swing.BorderFactory;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
|
@ -29,6 +31,8 @@ import javax.swing.JTable;
|
|||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.Color;
|
||||
import java.awt.SystemColor;
|
||||
|
@ -63,10 +67,11 @@ public class View_Courante {
|
|||
}
|
||||
}};
|
||||
frame.addWindowListener( wa ) ;
|
||||
|
||||
menu = new JMenuBar();
|
||||
|
||||
//Create and set up the panel.
|
||||
panel = new JPanel(new GridLayout(3,1));
|
||||
panel.setForeground(SystemColor.menuText);
|
||||
panel = new JPanel(new GridLayout(3,1));
|
||||
panel.setForeground(SystemColor.menuText);
|
||||
|
||||
//Add the widgets.
|
||||
this.addWidgets();
|
||||
|
@ -91,67 +96,146 @@ public class View_Courante {
|
|||
*/
|
||||
private void addWidgets() {
|
||||
jlabel = new JLabel(new ImageIcon("/Users/auriane/Desktop/ChatApp-AL-NM/Implementation/src/images/Logo.png"), JLabel.CENTER);
|
||||
menu = new JMenuBar();
|
||||
JMenu Actions = new JMenu("Actions");
|
||||
Actions.setForeground(Color.WHITE);
|
||||
Actions.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
// Définir le sous-menu pour Actions
|
||||
JMenuItem actifs = new JMenuItem("Utilisateurs actifs");
|
||||
JMenuItem session = new JMenuItem("Session de Clavardage");
|
||||
JMenuItem pseudo = new JMenuItem("Modifier Pseudo");
|
||||
JMenuItem deconnexion = new JMenuItem("Deconnexion");
|
||||
|
||||
actifs.addActionListener( new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
|
||||
} });
|
||||
session.addActionListener( new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
|
||||
} });
|
||||
pseudo.addActionListener( new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
panel.remove(jlabel);
|
||||
panel.remove(Txt);
|
||||
JLabel Text = new JLabel("Entrez un nouveau nom d'utilisateur!", SwingConstants.CENTER);
|
||||
JTextField pseudofield = new JTextField(2); // Zone d'insertion de texte
|
||||
panel.add(pseudofield);
|
||||
panel.add(Text);
|
||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
frame.setVisible(true);
|
||||
String pseudo = pseudofield.getText();
|
||||
try {
|
||||
app.modifierPseudo(pseudo);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// IL FAUT RAJOUTER UN BOUTON ENTRRE
|
||||
// IL FAUT MODIFIER "MODIFIER PSEUDO" pour que ca renvoit un boolean
|
||||
//Selon le boolean on affiche un pop up ou on renvient au menu principal en faisant new view courante
|
||||
}
|
||||
});
|
||||
deconnexion.addActionListener( new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
|
||||
} });
|
||||
|
||||
Actions.add(actifs);
|
||||
Actions.add(session);
|
||||
Actions.add(pseudo);
|
||||
Actions.add(deconnexion);
|
||||
|
||||
|
||||
menu.add(Actions);
|
||||
|
||||
|
||||
Txt = new JLabel("Menu principal de " + app.getMe().getPseudo());
|
||||
Txt.setFont(new Font("Tamil MN", Font.PLAIN, 30));
|
||||
Txt.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
panel.add(BorderLayout.NORTH , menu);
|
||||
panel.add(BorderLayout.CENTER, jlabel);
|
||||
panel.add(BorderLayout.SOUTH , Txt );
|
||||
JMenu Actions = new JMenu("Actions");
|
||||
Actions.setForeground(Color.WHITE);
|
||||
Actions.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
// Définir le sous-menu pour Actions
|
||||
JMenuItem actifs = new JMenuItem("Utilisateurs actifs");
|
||||
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 );
|
||||
|
||||
//******************************************************************************************************************
|
||||
//**************************************** Actions lorsque l'on clique sur actifs **********************************
|
||||
//******************************************************************************************************************
|
||||
actifs.addActionListener( new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
JPanel panel1 = new JPanel();
|
||||
JButton home = new JButton(new ImageIcon("/Users/auriane/Desktop/ChatApp-AL-NM/Implementation/src/images/Home.png"));
|
||||
panel1.add(BorderLayout.NORTH , home);
|
||||
|
||||
JLabel Text = new JLabel("<html> Liste Utilisateurs Actifs <br/> <html>");
|
||||
panel1.add(Text);
|
||||
|
||||
String utilisateurs = app.getActifUsers().afficherListeUtilisateurs();
|
||||
for(String elem : utilisateurs.split("\n")) {
|
||||
JLabel Text1 = new JLabel("<html>" + elem + "<br/> <html>");
|
||||
panel1.add(Text1);
|
||||
}
|
||||
|
||||
home.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
frame.dispose();
|
||||
new View_Courante(app);
|
||||
} });
|
||||
|
||||
frame.getContentPane().removeAll();
|
||||
frame.getContentPane().add(panel1);
|
||||
frame.setVisible(true);
|
||||
}});
|
||||
|
||||
//******************************************************************************************************************
|
||||
//**************************************** Actions lorsque l'on clique sur Session *********************************
|
||||
//******************************************************************************************************************
|
||||
session.addActionListener( new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
JButton home = new JButton(new ImageIcon("/Users/auriane/Desktop/ChatApp-AL-NM/Implementation/src/images/Home.png"));
|
||||
home.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
frame.dispose();
|
||||
new View_Courante(app);
|
||||
} });
|
||||
String utilisateurs = app.getActifUsers().afficherListeUtilisateurs();
|
||||
Vector<String> vector = new Vector<String>();
|
||||
for(String elem : utilisateurs.split("\n")) {
|
||||
vector.add(elem);
|
||||
}
|
||||
// Créer une liste déroulante
|
||||
JComboBox cb = new JComboBox(vector);
|
||||
cb.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
Object selected = cb.getSelectedItem();
|
||||
new View_Clavardage(app, selected.toString());
|
||||
|
||||
}
|
||||
});
|
||||
JPanel panel1 = new JPanel(new GridLayout(2,1));
|
||||
panel1.add(home);
|
||||
panel1.add(cb);
|
||||
frame.getContentPane().removeAll();
|
||||
frame.getContentPane().add(panel1,BorderLayout.CENTER);
|
||||
frame.setVisible(true);
|
||||
} });
|
||||
|
||||
//******************************************************************************************************************
|
||||
//**************************************** Actions lorsque l'on clique sur Pseudo **********************************
|
||||
//******************************************************************************************************************
|
||||
pseudo.addActionListener( new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
JLabel Text = new JLabel("Entrez un nouveau nom d'utilisateur!", SwingConstants.CENTER);
|
||||
JTextField pseudofield = new JTextField(2); // Zone d'insertion de texte
|
||||
JButton home = new JButton(new ImageIcon("/Users/auriane/Desktop/ChatApp-AL-NM/Implementation/src/images/Home.png"));
|
||||
home.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
frame.dispose();
|
||||
new View_Courante(app);
|
||||
} });
|
||||
//Ajout d'un bouton Valider
|
||||
JButton Valider = new JButton("Valider");
|
||||
frame.getRootPane().setDefaultButton(Valider);
|
||||
//Listen to events from the Valider button.
|
||||
Valider.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String nouveau = pseudofield.getText();
|
||||
try {
|
||||
Boolean resultat = app.modifierPseudo(nouveau);
|
||||
if(resultat) {
|
||||
JOptionPane.showMessageDialog(frame, "Modification pseudo Reussi");
|
||||
frame.dispose();
|
||||
new View_Courante(app);
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(frame, "Echec Modification pseudo ");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
JPanel panel1 = new JPanel(new GridLayout(4,1));
|
||||
panel1.add(home);
|
||||
panel1.add(Text);
|
||||
panel1.add(pseudofield);
|
||||
panel1.add(Valider);
|
||||
frame.getContentPane().removeAll();
|
||||
frame.getContentPane().add(panel1,BorderLayout.CENTER);
|
||||
frame.setVisible(true);
|
||||
}});
|
||||
//******************************************************************************************************************
|
||||
//**************************************** Actions lorsque l'on clique sur Deconnexion *****************************
|
||||
//******************************************************************************************************************
|
||||
deconnexion.addActionListener( new ActionListener(){
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
|
||||
} });
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
バイナリ
Implementation/src/images/Home.png
ノーマルファイル
バイナリ
Implementation/src/images/Home.png
ノーマルファイル
バイナリファイルは表示されません。
変更後 幅: | 高さ: | サイズ: 6.7 KiB |
読み込み中…
新しいイシューから参照