Hi, I want to write a messenger application with java. I want to send smily pictures. I have written this code but it doesn’t work.
public class MyClient extends JFrame implements IClient {
…
JEditorPane editorPane=new JEditorPane();
final String SMILE = ClassLoader.getSystemClassLoader().getResource("images/1.gif").toString();
…
public void chat(String message) {
try {
StringBuffer bfr= new StringBuffer(message);
while(message.indexOf(":)") != -1) {
int index = message.indexOf(":)");
bfr.replace(index,index+2,"<IMG SRC=\""+SMILE +"\">");
message= bfr.toString();
}
try{
editorPane.getEditorKit().read(new java.io.StringReader(message+"\n"),
editorPane.getDocument(), editorPane.getDocument().getLength());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
editorPane.setCaretPosition(editorPane.getDocument().getLength());
}
… But it desnt show the smily in the editorpane, the output is : It is the address with which the smily has been saved. I cast the code like this:
(HTMLEditorKit)editorPane.getEditorKit().read(new java.io.StringReader(message+"\n"),
editorPane.getDocument(), editorPane.getDocument().getLength());
but it causes exception as this cast isn’t correct. So what I can I do? thank