package tp4_reseau;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.UnknownHostException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JOptionPane;

public class ClientChatMulticast {
	final public static int PORT = 2000;
	final public static String HOST = "238.0.0.25";
	
	public static void main(String[] args) throws IOException {

        final FenetreChat fc = new FenetreChat("La folie du chat");
        String pseudo = JOptionPane.showInputDialog("Pseudo", "Poireau Volant") + " : ";
        Scanner sc = new Scanner(System.in);
        final MulticastSocket socket = new MulticastSocket(PORT);
        socket.joinGroup(InetAddress.getByName(HOST));
        
        fc.capturerEntree(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if(e.getKeyCode() == KeyEvent.VK_ENTER){
                    byte[] msg = (pseudo + fc.getMessage()).getBytes();
                    try {
                        DatagramPacket packet = new DatagramPacket(
                                msg,
                                msg.length,
                                InetAddress.getByName(HOST),
                                PORT
                        );
                        socket.send(packet);
                        fc.effacerChampEnvoi();
                    } catch (UnknownHostException ex) {
                        Logger.getLogger(ClientChatMulticast.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IOException ex) {
                        Logger.getLogger(ClientChatMulticast.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        });
        
        byte[] buff = new byte[256];
        DatagramPacket packet = new DatagramPacket(buff, buff.length);
        
        for(;;){
            socket.receive(packet);
            String msg = new String(packet.getData(), packet.getOffset(), packet.getLength());
            fc.afficherMessage(msg);
        }
    }

}

@@ -1,538 +1,688 @@
-package tp4_reseau;%0A%0Aimport java.awt.event.KeyAdapter;%0Aimport java.awt.event.KeyEvent;%0Aimport java.io.IOException;%0Aimport java.net.DatagramPacket;%0Aimport java.net.InetAddress;%0Aimport java.net.MulticastSocket;%0Aimport java.net.UnknownHostException;%0Aimport java.util.Scanner;%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A%0Aimport javax.swing.JOptionPane;%0A%0Apublic class ClientChatMulticast %7B%0A%09final public static int PORT = 2000;%0A%09final public static String HOST = %22238.0.0.25%22;%0A%09%0A%09public static void main(String%5B%5D args
+/*%0A * To change this license header, choose License Headers in Project Properties.%0A * To change this template file, choose Tools %7C Templates%0A * and open the template in the editor.%0A */%0A%0Apackage PoireauChat.Client.Views;%0A%0Aimport java.awt.BorderLayout;%0Aimport java.awt.Container;%0Aimport java.awt.event.KeyListener;%0Aimport java.awt.event.WindowListener;%0Aimport java.io.IOException;%0Aimport javax.swing.JFrame;%0Aimport javax.swing.JScrollPane;%0Aimport javax.swing.JTextArea;%0Aimport javax.swing.JTextField;%0A%0A/**%0A *%0A * @author Ga%C3%ABtan%0A */%0A%0A%0Apublic class FenetreChat extends JFrame %7B%0A%0A    private JTextArea zoneDiscussion;%0A    private JTextField champEnvoi;%0A%0A    public FenetreChat (String titre
 ) th
@@ -700,25 +700,24 @@
 ption %7B%0A
-%0A
         
 final Fe
@@ -712,76 +712,71 @@
     
-final FenetreChat fc = new FenetreChat(%22La folie du chat%22
+super(titre);%0A%0A        setBounds(600, 300, 400, 400
 );%0A
+%0A
         
 Stri
@@ -775,142 +775,112 @@
     
-String pseudo = JOptionPane.showInputDialog(%22Pseudo%22, %22Poireau Volant%22) + %22 : %22;%0A        Scanner sc = new Scanner(System.in
+Container conteneur = getContentPane();%0A        conteneur.setLayout(new BorderLayout(20, 20)
 );%0A
+%0A
         
 fina
@@ -879,1471 +879,922 @@
     
-final MulticastSocket socket = new MulticastSocket(PORT);%0A        socket.joinGroup(InetAddress.getByName(HOST));%0A        %0A        fc.capturerEntree(new KeyAdapter() %7B%0A            @Override%0A            public void keyPressed(KeyEvent e) %7B%0A                if(e.getKeyCode() == KeyEvent.VK_ENTER)%7B%0A                    byte%5B%5D msg = (pseudo + fc.getMessage()).getBytes();%0A                    try %7B%0A                        DatagramPacket packet = new DatagramPacket(%0A                                msg,%0A                                msg.length,%0A                                InetAddress.getByName(HOST),%0A                                PORT%0A                        );%0A                        socket.send(packet);%0A                        fc.effacerChampEnvoi();%0A                    %7D catch (UnknownHostException ex) %7B%0A                        Logger.getLogger(ClientChatMulticast.class.getName()).log(Level.SEVERE, null, ex);%0A                    %7D catch (IOException ex) %7B%0A                        Logger.getLogger(ClientChatMulticast.class.getName()).log(Level.SEVERE, null, ex);%0A                    %7D%0A                %7D%0A            %7D%0A        %7D);%0A        %0A        byte%5B%5D buff = new byte%5B256%5D;%0A        DatagramPacket packet = new DatagramPacket(buff, buff.length);%0A        %0A        for(;;)%7B%0A            socket.receive(packet);%0A            String msg = new String(packet.getData(), packet.getOffset(), packet.getLength());%0A            fc.afficherMessage(msg);%0A        %7D
+zoneDiscussion = new JTextArea();%0A        conteneur.add(zoneDiscussion, BorderLayout.CENTER);%0A%0A        JScrollPane barreDefilement = new JScrollPane(zoneDiscussion);%0A        conteneur.add(barreDefilement);%0A%0A        zoneDiscussion.setEditable(false);%0A%0A        champEnvoi = new JTextField();%0A        conteneur.add(champEnvoi, BorderLayout.SOUTH);%0A%0A        setVisible(true);%0A%0A    %7D%0A%0A    public void afficherMessage(String msg) %7B%0A        zoneDiscussion.append(msg + %22%5Cn%22);%0A        zoneDiscussion.setCaretPosition(zoneDiscussion.getDocument().getLength());%0A    %7D%0A%0A    public void effacerChampEnvoi() %7B%0A        champEnvoi.setText(%22%22);%0A    %7D%0A%0A    public String getMessage() %7B%0A        return champEnvoi.getText();%0A    %7D%0A%0A    public void capturerEntree(KeyListener listener) %7B%0A        champEnvoi.addKeyListener(listener);%0A    %7D%0A%0A    public void gererFermeture(WindowListener listener) %7B%0A        addWindowListener(listener);
 %0A   

Update FenetreChat.java