Envoi des messages fonctionne

This commit is contained in:
Morgane Foussats 2020-12-27 18:21:46 +01:00
parent 43fa39f42b
commit 5222751b1f
5 changed files with 22 additions and 18 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -136,7 +136,7 @@ public class DataBase {
idSrc = id2;
idDest = id1;
}
String nameTable = idSrc+""+idDest;
String nameTable = idSrc+"_"+idDest;
String query = "CREATE TABLE " +nameTable+" (\n" +
"id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, \n" +
"idSrc INT NOT NULL,\n" +
@ -163,14 +163,14 @@ public class DataBase {
idDest = id1;
}
String nameTable = idSrc+"_"+idDest;
String query = "SELECT * FROM" + nameTable;
String query = "SELECT * FROM " + nameTable;
PreparedStatement pStat = null;
try {
pStat = connexion.prepareStatement(query);
pStat.executeQuery();
}catch(SQLException e) {
res = false;
e.printStackTrace();
//e.printStackTrace();
}
return res;
}

View file

@ -63,7 +63,7 @@ public class FenetreChat extends JFrame{
this.panel = new JPanel();
//zone pour rentrer les message à envoyer
JTextArea text = new JTextArea(10, 7);
JTextArea text = new JTextArea(10, 3);
text.setForeground(Color.BLACK);
text.setFont(new Font("Century Schoolbook", Font.PLAIN, 11));
text.setText("Enter your message");
@ -71,6 +71,19 @@ public class FenetreChat extends JFrame{
JScrollPane sp = new JScrollPane(text);
//zone affichage texte
this.ta = new JTextArea(20, 20);
this.ta.setLineWrap(true);
this.ta.setText("");
JScrollPane sp2 = new JScrollPane(ta);
this.ta.setEditable(false);
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(0, 0, 5, 0);
gbc.gridx = 0;
gbc.gridy = 1;
frame.getContentPane().add(sp2, gbc);
//bouton envoyer
JButton envoyer = new JButton("Send");
frame.getRootPane().setDefaultButton(envoyer);
@ -90,6 +103,10 @@ public class FenetreChat extends JFrame{
tcpChat = tcp;
}
}
//text.append(message);
text.setText("");
ta.append(agent.getUser().getPseudo()+ " : "+message+"\n");
//ta.setText("");
tcpChat.sendMsg(message);
if(agent.getDb().tableChatExists(idUser, idDest)) {
agent.getDb().addMessage(idUser, idDest, message);
@ -101,21 +118,8 @@ public class FenetreChat extends JFrame{
System.out.println("Envoi du message impossible");
e1.printStackTrace();
}
text.append(message);
text.setText("");
}});
//zone affichage texte
this.ta = new JTextArea(10, 10);
this.ta.setLineWrap(true);
this.ta.setText("");
JScrollPane sp2 = new JScrollPane(ta);
this.ta.setEditable(false);
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(0, 0, 5, 0);
gbc.gridx = 0;
gbc.gridy = 1;
frame.getContentPane().add(sp2, gbc);
panel.add(BorderLayout.CENTER, sp);
panel.add(BorderLayout.SOUTH,envoyer);