My code is :
/b
import javax.swing.*;
import java.awt.*;
//import java.awt.event.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.filter.*;
public class Fenetre extends JFrame implements PacketListener{
public XMPPConnection con;
public JPanel global, ecrire;
public JTextArea ecr, rec;
public JScrollPane scrollecr, scrollrec;
public JButton envoi;
public static Chat chat;
public PacketListener myListener;
public PacketFilter filter;
public Fenetre(){
this.setSize(400,200);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.global = new JPanel();
this.global.setLayout(new BorderLayout());
this.ecr = new JTextArea();
this.rec = new JTextArea();
this.rec.setEditable(false);
this.rec.setRows(7);
this.ecr.setRows(3);
this.ecr.setLineWrap(true);
this.rec.setLineWrap(true);
this.envoi = new JButton(“Envoyer”);
this.scrollecr = new JScrollPane(this.ecr);
this.scrollrec = new JScrollPane(this.rec);
this.ecrire = new JPanel();
this.ecrire.setLayout(new BorderLayout());
this.ecrire.add(scrollecr, BorderLayout.CENTER);
this.ecrire.add(envoi, BorderLayout.EAST);
this.global.add(scrollrec, BorderLayout.CENTER);
this.global.add(ecrire, BorderLayout.SOUTH);
this.add(global);
this.setTitle(“Conversation Window Test”);
this.setVisible(true);
boolean co = this.createConnexion();
if (co){
this.setTitle(“Connected”);
}
this.envoi.addActionListener(new Action_Listener(this));
this.filter = new PacketTypeFilter(Message.class);
this.con.addPacketListener(this, filter);
}
public boolean createConnexion(){
try{
//Create a connection to the jivesoftware.com XMPP server.
XMPPConnection.DEBUG_ENABLED = true;
XMPPConnection con = new XMPPConnection(“yourserver”);
// Most servers require you to login before performing other tasks.
con.login(“your username”, "your pasword);
this.chat = con.createChat(“username of friend”);
filter = new PacketTypeFilter(Message.class);
con.addPacketListener(this, filter);
return true;
}catch(XMPPException e){
e.getMessage();
return false;
}
}
public void processPacket(Packet packet) {
Message message = (Message)packet;
String from = message.getFrom();
String body = message.getBody();
this.rec.append(this.chat.getParticipant()+ " dit : \n " + body + “\n”);
}
public static void main (String[] args){
Fenetre fen = new Fenetre();
}
}
Thanks for help
EDIT : I’‘ve found that my exception came from the listener in the constructor that i’‘ve forget to remove … then I’'ve no Exception when I run the program but the messages null when I chat with a spark client are always receive.
I can made a filter when the received message body is null but I don’‘t know if it’'s the best solution…
Message was edited by: Slashsnakit