modification background + serveur
這個提交存在於:
父節點
f5b3031ec4
當前提交
e38338000f
共有 16 個檔案被更改,包括 143 行新增 和 90 行删除
二進制
chatGit/background.jpg
一般檔案
二進制
chatGit/background.jpg
一般檔案
未顯示二進位檔案。
之後 寬度: | 高度: | 大小: 290 KiB |
未顯示二進位檔案。
未顯示二進位檔案。
未顯示二進位檔案。
未顯示二進位檔案。
未顯示二進位檔案。
未顯示二進位檔案。
未顯示二進位檔案。
未顯示二進位檔案。
未顯示二進位檔案。
未顯示二進位檔案。
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"serveur":{
|
||||
"actif": 1,
|
||||
"url": "http://localhost:8080/test/toto",
|
||||
"url": "https://srv-gei-tomcat.insa-toulouse.fr/barnabeFoussats/toto",
|
||||
"port": 8080
|
||||
},
|
||||
"config":{
|
||||
|
|
|
@ -174,7 +174,7 @@ public class Agent implements PropertyChangeListener{
|
|||
public boolean connectInscription(String pseudo, String login) throws IOException, InterruptedException {
|
||||
MessagePseudo msg_connexion = new MessagePseudo(this.localAddress, this.broadcast, this.user.getPort(), App.portDest, 0, "", this.user.getId());
|
||||
BOut.send(msg_connexion, this.broadcast, App.portDest);
|
||||
Thread.sleep(5000);
|
||||
Thread.sleep(2000);
|
||||
ArrayList<MessagePseudo> msg_recus = BIn.getListMessage();
|
||||
for(int i =0; i<msg_recus.size(); i++) {
|
||||
handleMessage(msg_recus.get(i));
|
||||
|
@ -200,7 +200,7 @@ public class Agent implements PropertyChangeListener{
|
|||
public boolean connectConnexion(String pseudo, String login) throws IOException, InterruptedException {
|
||||
MessagePseudo msg_connexion = new MessagePseudo(this.localAddress, this.broadcast, this.user.getPort(), App.portDest, 0, "", this.user.getId());
|
||||
BOut.send(msg_connexion, this.broadcast, App.portDest);
|
||||
Thread.sleep(5000);
|
||||
Thread.sleep(2000);
|
||||
ArrayList<MessagePseudo> msg_recus = BIn.getListMessage();
|
||||
for(int i =0; i<msg_recus.size(); i++) {
|
||||
handleMessage(msg_recus.get(i));
|
||||
|
|
|
@ -47,13 +47,7 @@ public class FenetreInscription implements ActionListener {
|
|||
panel = new JPanel(new GridLayout(7,1));
|
||||
//Ajouter les elements
|
||||
this.addWidgets();
|
||||
//Set the default button.
|
||||
//frame.getRootPane().setDefaultButton(inscription);
|
||||
//frame.getRootPane().setDefaultButton(connexion);
|
||||
//frame.setLayout(new BorderLayout());
|
||||
//On ajoute le bouton au content pane de la JFrame
|
||||
//frame.getContentPane().add(inscription, BorderLayout.CENTER);
|
||||
//frame.getContentPane().add(connexion, BorderLayout.SOUTH);
|
||||
frame.getRootPane().setDefaultButton(inscription);
|
||||
//Ajouter le panel a la window
|
||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
//L'utilisateur ne pourra pas aggrandir la fenetre
|
||||
|
|
|
@ -4,14 +4,17 @@ import java.awt.BorderLayout;
|
|||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.Image;
|
||||
import java.awt.SystemColor;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
|
||||
|
@ -53,7 +56,7 @@ public class FenetreMenu {
|
|||
frame = new JFrame("Fenêtre menu");
|
||||
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
|
||||
frame.setSize(new Dimension(100, 100));
|
||||
frame.setSize(new Dimension(500, 800));
|
||||
|
||||
wa = new WindowAdapter(){
|
||||
public void windowClosing(WindowEvent e){
|
||||
|
@ -76,8 +79,20 @@ public class FenetreMenu {
|
|||
//Creation d'un JPanel
|
||||
panel = new JPanel(new GridLayout(3,1));
|
||||
panel.setForeground(SystemColor.menuText);
|
||||
panel.setOpaque(false);
|
||||
// Ajouter tout les elements a la fenetre
|
||||
this.addWidgets();
|
||||
|
||||
try {
|
||||
final Image backgroundImage = javax.imageio.ImageIO.read(new File("background.jpg"));
|
||||
frame.setContentPane(new JPanel(new BorderLayout()) {
|
||||
@Override public void paintComponent(Graphics g) {
|
||||
g.drawImage(backgroundImage, 0, 0, null);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// ajouter le panel a la fenetre
|
||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
// Afficher la fenetre
|
||||
|
@ -95,19 +110,19 @@ public class FenetreMenu {
|
|||
|
||||
private void addWidgets() throws IOException {
|
||||
jlabel = new JLabel(new ImageIcon("panda.png"), JLabel.CENTER);
|
||||
texte = new JLabel("Bienvenue sur ce magnifique chat " + agent.getUser().getPseudo());
|
||||
texte.setFont(new Font("Century Schoolbook", Font.PLAIN, 40));
|
||||
texte.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
liste = new JLabel("Active users", JLabel.LEFT);
|
||||
jlabel.setOpaque(false);
|
||||
texte = new JLabel();
|
||||
texte.setOpaque(false);
|
||||
texte.setFont(new Font("Century Schoolbook", Font.PLAIN, 60));
|
||||
texte.setText("<html><font color = #F7F9F9>Bienvenue sur le tchat</font></html>");
|
||||
texte.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
liste = new JLabel("Active users", JLabel.LEFT);
|
||||
liste.setOpaque(false);
|
||||
|
||||
JMenu contenu = new JMenu("Actions");
|
||||
contenu.setForeground(Color.BLUE);
|
||||
contenu.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
JButton refresh = new JButton("Refresh");
|
||||
refresh.setForeground(Color.GRAY);
|
||||
refresh.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
//JMenuItem usersActifs = new JMenuItem("Active users");
|
||||
JMenuItem modifierPseudo = new JMenuItem("Modify your pseudo");
|
||||
JMenuItem deco = new JMenuItem("Deconnection");
|
||||
|
@ -118,7 +133,6 @@ public class FenetreMenu {
|
|||
|
||||
|
||||
menu.add(contenu);
|
||||
menu.add(refresh);
|
||||
frame.setJMenuBar(menu);
|
||||
|
||||
/*liste déroulante des utilsateurs actifs,
|
||||
|
@ -156,32 +170,6 @@ public class FenetreMenu {
|
|||
});
|
||||
|
||||
|
||||
/*actions pour refresh*/
|
||||
/* refresh.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String users = agent.getList().actifUsers();
|
||||
for(String pseudo : users.split("\n")) {
|
||||
if (!v.contains(pseudo)) {
|
||||
v.add(pseudo);
|
||||
}
|
||||
}
|
||||
JComboBox cb = new JComboBox(v);
|
||||
cb.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
Object selected = cb.getSelectedItem();
|
||||
int idDest = agent.getDb().getIdFromPseudo(selected.toString());
|
||||
try {
|
||||
agent.createChat(idDest, selected.toString());
|
||||
} catch (IOException e) {
|
||||
System.out.println("Creation tcp chat impossible");
|
||||
e.printStackTrace();
|
||||
}
|
||||
new FenetreChat(agent, selected.toString());
|
||||
}
|
||||
});
|
||||
}});*/
|
||||
|
||||
frame.getContentPane().add(refresh, BorderLayout.NORTH);
|
||||
panel.add(BorderLayout.CENTER, jlabel);
|
||||
panel.add(BorderLayout.SOUTH , texte );
|
||||
panel.add(BorderLayout.WEST, cb);
|
||||
|
@ -190,50 +178,14 @@ public class FenetreMenu {
|
|||
|
||||
|
||||
/*actions pour modifier le pseudo*/
|
||||
modifierPseudo.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JLabel Text = new JLabel("Enter your new pseudo", SwingConstants.CENTER);
|
||||
JTextField field = new JTextField(2);
|
||||
JButton cancel = new JButton("Cancel");
|
||||
cancel.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
frame.dispose();
|
||||
try {
|
||||
new FenetreMenu(agent);
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}});
|
||||
JButton ok = new JButton("Continue");
|
||||
frame.getRootPane().setDefaultButton(ok);
|
||||
ok.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String newPseudo = field.getText();
|
||||
try {
|
||||
if(agent.changerPseudo(newPseudo)) {
|
||||
JOptionPane.showMessageDialog(frame, "Your new pseudo is "+newPseudo);
|
||||
frame.dispose();
|
||||
new FenetreMenu(agent);
|
||||
}else {
|
||||
JOptionPane.showMessageDialog(frame, "Pseudo already, use choose another one");
|
||||
}
|
||||
} catch (HeadlessException | IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
};
|
||||
}
|
||||
});
|
||||
JPanel panel1 = new JPanel(new GridLayout(4,1));
|
||||
panel1.add(cancel);
|
||||
panel1.add(Text);
|
||||
panel1.add(field);
|
||||
panel1.add(ok);
|
||||
frame.getContentPane().removeAll();
|
||||
frame.getContentPane().add(panel1,BorderLayout.CENTER);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
modifierPseudo.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
frame.dispose();
|
||||
new FenetreModifPseudo(agent);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
deco.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
package gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import controller.*;
|
||||
|
||||
public class FenetreModifPseudo implements ActionListener {
|
||||
JFrame frame;
|
||||
JPanel panel;
|
||||
JTextField pseudofield;
|
||||
JLabel Text;
|
||||
JButton ok;
|
||||
JButton Cancel;
|
||||
Agent agent;
|
||||
|
||||
/*
|
||||
* 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 FenetreModifPseudo(Agent agent) {
|
||||
this.agent = agent;
|
||||
//creer une instance JFrame
|
||||
frame = new JFrame("Modification pseudo");
|
||||
//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));
|
||||
//Creer le JPanel
|
||||
panel = new JPanel(new GridLayout(4,1));
|
||||
//Ajouter les elements
|
||||
this.addWidgets();
|
||||
//Set the default button.
|
||||
frame.getRootPane().setDefaultButton(ok);
|
||||
//Ajouter le panel a la window
|
||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
//L'utilisateur ne pourra pas aggrandir la fenetre
|
||||
this.frame.setResizable(false);
|
||||
//Afficher la fenetre
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private void addWidgets() {
|
||||
// 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("Type your new pseudo", SwingConstants.CENTER);
|
||||
//Ajout d'un bouton Connexion
|
||||
this.ok = new JButton("Continue");
|
||||
this.Cancel = new JButton("Cancel");
|
||||
this.ok.addActionListener(this);
|
||||
this.Cancel.addActionListener(this);
|
||||
//On associe au bouton Connexion des actions a realiser
|
||||
this.ok.addActionListener(this);
|
||||
// On ajouter les differents elements au panel
|
||||
panel.add(pseudofield);
|
||||
panel.add(Text);
|
||||
panel.add(ok);
|
||||
panel.add(Cancel);
|
||||
//ajouter un effet de bord transparent au composant Jlabel
|
||||
Text.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
Object source = event.getSource();
|
||||
if(source == ok){
|
||||
String newPseudo = pseudofield.getText();
|
||||
try {
|
||||
if(agent.changerPseudo(newPseudo)) {
|
||||
JOptionPane.showMessageDialog(frame, "Your new pseudo is "+newPseudo);
|
||||
frame.dispose();
|
||||
new FenetreMenu(agent);
|
||||
}else {
|
||||
JOptionPane.showMessageDialog(frame, "Pseudo already, use choose another one");
|
||||
}
|
||||
} catch (HeadlessException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
};
|
||||
}else if(source == Cancel) {
|
||||
frame.dispose();
|
||||
try {
|
||||
new FenetreMenu(agent);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
載入中…
新增問題並參考