How to replace string with image( Say Smiley).........?

Hello To All Experts !!

I wanna looking for some help in displaying image in my text area when should i type ":)" in text field.....

I got some program through forums....

import java.util.*;

import javax.swing.ImageIcon;

publicclass TokenizeSmiley{

privatestaticfinal HashMap SMILEYS;

static{

SMILEYS =new HashMap();

SMILEYS.put(":)",new ImageIcon("images/1.gif"));

SMILEYS.put(";)","<wink>");

}

publicstaticvoid main(String[] args){

String text ="Hello!! :) How are you ;)";

StringTokenizer st =new StringTokenizer(text);

String token;

while (st.hasMoreTokens()){

token = st.nextToken();

if (SMILEYS.containsKey(token))

token = (String)SMILEYS.get(token);

System.out.print(token +" ");

}

}

}

but it is showing <smile> and <wink> as it is given...i tried to give path of image ...but it is nt fetching then also.....

Plz help in this....

[1921 byte] By [Damz@dela] at [2007-10-3 9:54:06]
# 1
A text area cannot display images: use a JEditorPane instead.
Franck_Lefevrea at 2007-7-15 5:11:48 > top of Java-index,Desktop,Core GUI APIs...
# 2
I would use a JTextPane. Here is an example of inserting an icon into the text pane: http://javaalmanac.com/egs/javax.swing.text/tp_ImageText.html
camickra at 2007-7-15 5:11:48 > top of Java-index,Desktop,Core GUI APIs...
# 3
Thanks camikr...the program i posted in my new thread as u knw.......where should i include that JEditorPane Code.....i m bit confused in doing that.......
Damz@dela at 2007-7-15 5:11:48 > top of Java-index,Desktop,Core GUI APIs...
# 4
Well, I suggested using JTextPane as was indicated by the link I provided you.Also if you search the forum using "smiley" you will find other postings on this topic. Some even have working solutions.
camickra at 2007-7-15 5:11:48 > top of Java-index,Desktop,Core GUI APIs...
# 5

Hi i got this code after searching.......

class smileyThread implements Runnable

{

public void run()

{

try

{

StyledDocument doc2=chc.tachatarea.getStyledDocument();

String text=doc2.getText(0,doc2.getLength());

SimpleAttributeSet smi;

int index;

int start=0;

char c;

index=text.indexOf(':');

while(index>-1)

{

synchronized(this){

Element e1=doc2.getCharacterElement(index);

if (StyleConstants.getIcon(e1.getAttributes()) == null)

{

if(index<text.length())c=text.charAt(index+1);

else break;

switch(c)

{

case ')':

doc2.remove(index,2);

smi=new SimpleAttributeSet();

StyleConstants.setIcon(smi,new ImageIcon("images\\smileys\\happy.gif"));

doc2.insertString(index,":)",smi);

start=(index+2);

break;

case '(':

doc2.remove(index,2);

smi=new SimpleAttributeSet();

StyleConstants.setIcon(smi,new ImageIcon("images\\smileys\\sad.gif"));

doc2.insertString(index,":(",smi);

start=(index+2);

break;

case '@':

doc2.remove(index,2);

smi=new SimpleAttributeSet();

StyleConstants.setIcon(smi,new ImageIcon("images\\smileys\\angry.gif"));

doc2.insertString(index,":@",smi);

start=(index+2);

break;

default:

start=(index+1);

}

}

else start=(index+1);

index=(text.indexOf(':',start));}

}

chc.tachatarea.setStyledDocument(doc2);

}

catch(BadLocationException exc)

{

System.out.println("Bad Location");

exc.printStackTrace();

}

}

}

but will you please tell me how should i include main method to run this program.....

And moreover i want to access my emoticons using this xml file.....

><chat>

...

<emoticon>

<text>:)</text>

<location>file_location_happy (classpath, url, file, etc..)</location>

</emoticon>

<text>:(</text>

<location>file_location_sad (classpath, url, file, etc..)</location>

</emoticon>

...

</chat>

Please help me in this regard

Damz@dela at 2007-7-15 5:11:48 > top of Java-index,Desktop,Core GUI APIs...
# 6
I hav read that thread also....i have the same problem and i want to read all my images throgh XML fileThis is link to that thread.... http://forum.java.sun.com/thread.jspa?threadID=774997&messageID=4413258
Damz@dela at 2007-7-15 5:11:48 > top of Java-index,Desktop,Core GUI APIs...
# 7
Keep searching I found one posting by stanislavl that was actual working code.
camickra at 2007-7-15 5:11:48 > top of Java-index,Desktop,Core GUI APIs...
# 8
yea i got that post by stanislavl.....But that must drwaing a component instead of calling image or reading from any source......can u tell me the method by which i read my images from its source path.....thanks
Damz@dela at 2007-7-15 5:11:48 > top of Java-index,Desktop,Core GUI APIs...
# 9

> But that must drwaing a component instead of calling image or reading from any source......

Its makes it easy to post code on the forum since you can't post the actual image.

> can u tell me the method by which i read my images from its source path.....

You can't be serious. The code you posted creates an ImageIcon. Did you copy that code from somewhere without understanding what it was doing?

camickra at 2007-7-15 5:11:48 > top of Java-index,Desktop,Core GUI APIs...
# 10
i m very serious .....I hav copy that code and also run that.......when i type :) this in text area....it will automatically makes an smiley oval......but this is nt any image calling........
Damz@dela at 2007-7-15 5:11:48 > top of Java-index,Desktop,Core GUI APIs...