1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;
import java.awt.event.*;
import java.awt.*;
public class FenetreDialogue extends JFrame {
protected JPanel panel,ecran, pied, entete;
protected JTextArea lecture,ecriture;
protected JButton envoyer;
protected ImageIcon fondecran;
protected JLabel lblimg;
protected JMenuBar menu;
protected JMenu contact, statut, ajout;
protected String titre,msg;
protected client c;
protected JScrollPane jsplecture,jspecriture;
public FenetreDialogue (client c,String titre){
super();
this.titre = titre;
this.c=c;
build();
ReceptionThreadClient.listeconvers.put(this.titre,this);
}
private void build(){
setTitle(this.titre);
setSize(400,200);
setLocationRelativeTo(null);//fenetre centree
setResizable(true);//interdit de redimensionner la fenetre
setContentPane(buildContentPane());
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
ReceptionThreadClient.listeconvers.remove(titre);
}
});
}
private JPanel buildContentPane(){
//Traitement du panel de pied de page
pied = new JPanel();
pied.setLayout(new GridLayout(1,1));
envoyer = new JButton("envoyer");
envoyer.addActionListener(new ActionListener (){
public void actionPerformed(ActionEvent evt){
msg=c.pseudo+" dit : \n"+ecriture.getText()+"\n";
lecture.append(msg);
msg="dial,";
msg=msg+c.pseudo+",";
msg=msg+titre+",";
msg=msg+ecriture.getText();
ecriture.setText("");
BoutonDialogue bd = new BoutonDialogue(c,msg);
bd.start();
}
});
envoyer.setDefaultCapable(true);
this.getRootPane().setDefaultButton(envoyer);
pied.add(envoyer);
//Traitement du panel central
ecran = new JPanel();
ecran.setLayout(new GridLayout(2,1,5,5));
lecture = new JTextArea();
jsplecture = new JScrollPane(lecture);
jsplecture.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
ecriture = new JTextArea();
jspecriture = new JScrollPane(ecriture);
jspecriture.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
ecran.add(jsplecture);
ecran.add(jspecriture);
//Traitement du panel principal
panel = new JPanel();
panel.setLayout(new BorderLayout());
//creation du menu
menu = new JMenuBar();
statut = new JMenu("Statut");
statut.add(new JMenu("Envoyer un fichier"));
statut.add(new JMenu("Se deconnecter"));
contact = new JMenu("Contact");
ajout = new JMenu("Ajouter un contact");
contact.add(ajout);
contact.add(new JMenu("Supprimer un contact"));
menu.add(statut);
menu.add(contact);
panel.add(menu,BorderLayout.BEFORE_FIRST_LINE);
panel.add(ecran,BorderLayout.CENTER);
panel.add(pied,BorderLayout.AFTER_LAST_LINE);
System.out.println(c.pseudo + " : " + this.titre);
return panel;
}
} |
Partager