import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class Chat extends JFrame { JButton b1 ,b2 ; JLabel label1, label2 , label3 ; JTextField txt1,txt2 ; JTextArea area1, area2 ; JMenuBar menubar ; JMenu menu ; JMenuItem item1 , item2, item3 ; MonClient client ; public JPanel creerPanneauBouton () { JButton b1 = new JButton ("Connexion") ; JButton b2 = new JButton ("Terminé") ; JPanel pan = new JPanel () ; pan.add (b1) ; pan.add (b2) ; ActionListener lstr1 = new ActionListener() { public void actionPerformed (ActionEvent e){ String hostName = txt1.getText(); int port = Integer.parseInt (txt2.getText ()) ; try { MonClient client = new MonClient (hostName , port ) ; } catch(IOException a) { System.err.println("erreur de realisation du client"+client); if (client != null){ client.fermer(); client = null; } } } }; b1.addActionListener(lstr1); return pan ; } public JPanel creerZoneText () { JTextArea area1 = new JTextArea (30,20) ; JTextArea area2 = new JTextArea (30,20) ; JLabel label1 = new JLabel ("Client") ; JLabel label2 = new JLabel ("Serveur"); JPanel pan1 = new JPanel () ; pan1.add (area1) ; pan1.add (area2) ; JPanel pan2 = new JPanel () ; pan2.add (label1) ; pan2.add (label2); JPanel pan3 = new JPanel () ; pan3.setLayout (new BoxLayout (pan3 , BoxLayout.Y_AXIS)); pan3.add (pan2) ; pan3.add(pan1); return pan3 ; } public JPanel creerZonehaute () { final JTextField txt1 = new JTextField (15) ; final JTextField txt2 = new JTextField (15) ; JLabel label3 = new JLabel ("Port") ; JLabel label2 = new JLabel ("Serveur"); JPanel pan1 = new JPanel () ; pan1.add (label2) ; pan1.add (txt1) ; JPanel pan2 = new JPanel () ; pan2.add (label3) ; pan2.add (txt2); JPanel pan3 = new JPanel () ; pan3.setLayout (new BoxLayout (pan3 , BoxLayout.Y_AXIS)); pan3.add (pan1) ; pan3.add(pan2); ActionListener lstr1 = new ActionListener() { public void actionPerformed (ActionEvent e){ String mess = txt1.getText(); System.out.println(mess); } }; txt1.addActionListener(lstr1); ActionListener lstr2 = new ActionListener() { public void actionPerformed (ActionEvent e){ String mess = txt2.getText(); System.out.println(mess); } }; txt2.addActionListener(lstr2); return pan3 ; } public JMenuBar creerbarredemenu () { JMenuBar menubar = new JMenuBar () ; JMenu menu = new JMenu ("Fichier") ; JMenuItem item1 = new JMenuItem ("Sélectionner",'S') ; JMenuItem item2 = new JMenuItem ("Enregistrer" , 'E') ; JMenuItem item3 = new JMenuItem ("Quitter", 'Q'); menu.add (item1); menu.add (item2) ; menu.add (item3) ; menubar.add (menu) ; this.setJMenuBar (menubar) ; ActionListener lstr = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; item3.addActionListener(lstr); return menubar ; } public Chat () { setTitle ("messenger") ; setDefaultCloseOperation(EXIT_ON_CLOSE); Container panneau = getContentPane () ; JPanel pb = creerPanneauBouton () ; panneau.add (pb , BorderLayout.SOUTH) ; JPanel pm = creerZoneText () ; panneau.add (pm , BorderLayout.CENTER) ; JPanel ph = creerZonehaute () ; panneau.add (ph , BorderLayout.NORTH) ; JMenuBar mb = creerbarredemenu () ; } public static void main(String args[]) { Chat f1 = new Chat(); f1.pack(); f1.setVisible(true); } }