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]

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