debut interface graphique

This commit is contained in:
Auriane Lartigue 2020-12-07 15:20:53 +01:00
parent ba901972cd
commit d034e30c2c
6 changed files with 266 additions and 84 deletions

View file

@ -129,6 +129,7 @@ public class ChatApp {
// Message que l'on envoie à tous les utilisateurs actifs
String broadcastMessage = "Deconnexion\n" + this.getMe().toString() ;
UDPEchange.EnvoiBroadcast(broadcastMessage);
System.exit(1);
}
/**

View file

@ -1,84 +0,0 @@
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class View extends JFrame {
public View() {
//créer une instance JFrame
super("ChatApp-AL-NM");
// creation d'un label qui contiendra un txt au centre
JLabel label = new JLabel("Bonjour, Entrez un nom d'utilisateur!", JLabel.CENTER);
// Définissez le panel (conteneur de différents composants)
JPanel panel = new JPanel();
// Définir le bouton
JButton btn1 = new JButton("Connexion");
// Ajouter le bouton au frame
panel.add(btn1);
/*****************************/
//L'en-têtes du JTable
String[] column = {"Pseudo", "port", "IP", "ID"};
//Les lignes du JTable
String[][] data = {
{"Auriane", "3000", "MBP-de-Auriane/192.168.1.43 ", "MBP-de-Auriane"},
{"Nabil", "4000", "LAPTOP-1JO2SHBG/192.168.1.72", "LAPTOP-1JO2SHBG"}
};
// Créer le JTable
JTable table = new JTable(data, column);
JScrollPane scroll = new JScrollPane(table);
// Ajout de la JTable
this.add(scroll);
// Définir le menu principal
JMenuBar menu = new JMenuBar();
JMenu pseudo= new JMenu("Modifier Pseudo");
JMenu clavardage = new JMenu("Clavardage");
JMenu deconnexion = new JMenu("Deconnexion");
// Définir le sous-menu pour Clavardage
JMenuItem actifs = new JMenuItem("Connaitre utilisateur actifs");
JMenuItem session = new JMenuItem("Demarrer session");
clavardage.add(actifs);
clavardage.add(session);
menu.add(pseudo);
menu.add(clavardage);
menu.add(deconnexion);
// Ajouter label, menu et panel au frame
this.setLayout(new GridLayout(8, 1));
this.add(menu);
this.add(label);
this.add(panel);
// fixer les dimensions de la fenêtre
this.pack();
this.setSize(500, 500);
//sortir quand lutilisateur ferme le frame
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// rendre la fenêtre visible :
this.setVisible(true);
}
public static void main (String[] args) {
JFrame frame = new View();
}
}

View file

@ -0,0 +1,107 @@
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.swing.BorderFactory;
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 View_Accueil implements ActionListener{
JFrame frame;
JPanel panel;
JTextField pseudofield;
JLabel Text;
JButton Connexion;
public View_Accueil () {
//creer une instance JFrame
frame = new JFrame("ChatApp-AL-NM");
//sortir quand lutilisateur 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.
panel = new JPanel(new GridLayout(3,1));
//Add the widgets.
this.addWidgets();
//Set the default button.
frame.getRootPane().setDefaultButton(Connexion);
//Add the panel to the window.
frame.getContentPane().add(panel, BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
}
/**
* Create and add the widgets.
*/
private void addWidgets() {
//Create widgets.
this.pseudofield = new JTextField(2); // Zone d'insertion de texte
// 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.
this.Connexion.addActionListener(this);
//Add the widgets to the container.
panel.add(pseudofield);
panel.add(Text);
panel.add(Connexion);
Text.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
}
public void actionPerformed(ActionEvent event) {
String pseudo = pseudofield.getText();
ChatApp app = new ChatApp(pseudo, 3000) ;
ExecutorService execUDP = Executors.newFixedThreadPool(1000);
execUDP.submit(new RunnerEcouteUDP(app));
try {
app.connexion();
} catch (IOException e) {
e.printStackTrace();
}
//JOptionPane.showMessageDialog(frame, "Bonjour " + pseudo);
frame.dispose();
View_Courante fenetreCourante= new View_Courante(app);
}
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
View_Accueil fenetre = new View_Accueil();
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}

View file

@ -0,0 +1,158 @@
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
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;
public class View_Courante {
JFrame frame;
JPanel panel;
JMenuBar menu;
ChatApp app;
JLabel jlabel;
JLabel Txt;
WindowAdapter wa ;
public View_Courante(ChatApp app) {
this.app = app ;
//creer une instance JFrame
frame = new JFrame("ChatApp-AL-NM");
//sortir quand lutilisateur ferme le frame
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
// fixer les dimensions de la fenetre
frame.setSize(new Dimension(394, 344));
wa = new WindowAdapter(){
public void windowClosing(WindowEvent e){
int reponse = showConfirmDialog();
if (reponse==0){
try {
app.deconnexion();
} catch (IOException e1) {
e1.printStackTrace();
}
frame.dispose();
}
}};
frame.addWindowListener( wa ) ;
//Create and set up the panel.
panel = new JPanel(new GridLayout(3,1));
panel.setForeground(SystemColor.menuText);
//Add the widgets.
this.addWidgets();
//Add the panel to the window.
frame.getContentPane().add(panel, BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
}
static int showConfirmDialog(){
return JOptionPane.showConfirmDialog(
null,
"Voulez-vous vraiment quitter?",
"Quitter",
JOptionPane.YES_NO_OPTION);
}
/**
* Create and add the widgets.
*/
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 );
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB