How to replace string with image using xml.........?
Hello All,
I am new to java and xml........
I am currently working on a messenger project.....
Currently i m looking for some help in my chat window code......
Actually when i run my messenger program....after login i got many users onlin and when i select a user to chat wid i got another chat window for it likewise in yahoo....
But the problem i m getting in is -
when i type :)) for a smiley image ...it will nt display in text area......
i m using following code to do this.....
while(str.indexOf("x(") != -1){
int index = str.indexOf("x(");
bfr.replace(index,index+2,"<IMG SRC=\""+ANGRY +"\">");
str= bfr.toString();
}
for above code i m using a chatconstants.java program in my package from where i m accesing all these images....
Actually i want to call my images using a XML file so i want to implement that code in XML and reads ir from a java program......
so i m looking for a correct XML file to read from java program......
Thanks in Advance......
[1289 byte] By [
Damz@dela] at [2007-10-3 9:46:14]

ok now i m clearing all thing here.....
I want to replace string with smiley icons.......
and all images are read through java code from XML file.....
private void appendData(String user,String str,boolean received)
{
StringBuffer bfr= new StringBuffer(str);
//private Variable recv;
while(str.indexOf("X(") != -1) {
int index = str.indexOf("X(");
bfr.replace(index,index+2,"<IMG SRC=\""+ANGRY +"\">");
str= bfr.toString();
}
while(str.indexOf("x(") != -1) {
int index = str.indexOf("x(");
bfr.replace(index,index+2,"<IMG SRC=\""+ANGRY +"\">");
str= bfr.toString();
}
while(str.indexOf(":))") != -1) {
int index = str.indexOf(":))");
bfr.replace(index,index+3,"<IMG SRC=\""+LAUGH +"\">");
str= bfr.toString();
}
while(str.indexOf(":((") != -1) {
int index = str.indexOf(":((");
bfr.replace(index,index+3,"<IMG SRC=\""+CRY +"\">");
str= bfr.toString();
}
while(str.indexOf("B-)") != -1) {
int index = str.indexOf("B-)");
bfr.replace(index,index+3,"<IMG SRC=\""+COOL +"\">");
str= bfr.toString();
}
while(str.indexOf("=;") != -1) {
int index = str.indexOf("=;");
bfr.replace(index,index+2,"<IMG SRC=\""+BYE +"\">");
str= bfr.toString();
}
while(str.indexOf(">:)") != -1) {
int index = str.indexOf(">:)");
bfr.replace(index,index+3,"<IMG SRC=\""+DEVIL +"\">");
str= bfr.toString();
}
while(str.indexOf(":|") != -1) {
int index = str.indexOf(":|");
bfr.replace(index,index+2,"<IMG SRC=\""+EQUISMILE +"\">");
str= bfr.toString();
}
while(str.indexOf(":-|") != -1) {
int index = str.indexOf(":-|");
bfr.replace(index,index+3,"<IMG SRC=\""+EQUISMILE +"\">");
str= bfr.toString();
}
while(str.indexOf(":-P") != -1) {
int index = str.indexOf(":-P");
bfr.replace(index,index+3,"<IMG SRC=\""+TONGUE +"\">");
str= bfr.toString();
}
while(str.indexOf(":P") != -1) {
int index = str.indexOf(":P");
bfr.replace(index,index+2,"<IMG SRC=\""+TONGUE +"\">");
str= bfr.toString();
}
while(str.indexOf(":-o") != -1) {
int index = str.indexOf(":-o");
bfr.replace(index,index+3,"<IMG SRC=\""+SURPRISE +"\">");
str= bfr.toString();
}
while(str.indexOf(":-O") != -1) {
int index = str.indexOf(":-O");
bfr.replace(index,index+3,"<IMG SRC=\""+SURPRISE +"\">");
str= bfr.toString();
}
while(str.indexOf("~0)") != -1) {
int index = str.indexOf("~0)");
bfr.replace(index,index+3,"<IMG SRC=\""+COFFEE +"\">");
str= bfr.toString();
}
while(str.indexOf("~o)") != -1) {
int index = str.indexOf("~o)");
bfr.replace(index,index+3,"<IMG SRC=\""+COFFEE +"\">");
str= bfr.toString();
}
while(str.indexOf(":>") != -1) {
int index = str.indexOf(":>");
bfr.replace(index,index+2,"<IMG SRC=\""+MEAN +"\">");
str= bfr.toString();
}
while(str.indexOf(":->") != -1) {
int index = str.indexOf(":->");
bfr.replace(index,index+3,"<IMG SRC=\""+MEAN +"\">");
str= bfr.toString();
}
while(str.indexOf(":\">") != -1) {
int index = str.indexOf(":\">");
bfr.replace(index,index+3,"<IMG SRC=\""+SHY +"\">");
str= bfr.toString();
}
while(str.indexOf(":-/") != -1) {
int index = str.indexOf(":-/");
bfr.replace(index,index+3,"<IMG SRC=\""+QUESTION +"\">");
str= bfr.toString();
}
while(str.indexOf(":O") != -1) {
int index = str.indexOf(":O");
bfr.replace(index,index+2,"<IMG SRC=\""+SURPRISE +"\">");
str= bfr.toString();
}
while(str.indexOf(":o") != -1) {
int index = str.indexOf(":o");
bfr.replace(index,index+2,"<IMG SRC=\""+SURPRISE +"\">");
str= bfr.toString();
}
while(str.indexOf(":(") != -1) {
int index = str.indexOf(":(");
bfr.replace(index,index+2,"<IMG SRC=\""+SAD +"\">");
str= bfr.toString();
}
while(str.indexOf(":-(") != -1) {
int index = str.indexOf(":-(");
bfr.replace(index,index+3,"<IMG SRC=\""+SAD +"\">");
str= bfr.toString();
}
while(str.indexOf(":)") != -1) {
int index = str.indexOf(":)");
bfr.replace(index,index+2,"<IMG SRC=\""+SMILE +"\">");
str= bfr.toString();
}
while(str.indexOf(":-)") != -1) {
int index = str.indexOf(":-)");
bfr.replace(index,index+3,"<IMG SRC=\""+SMILE +"\">");
str= bfr.toString();
}
while(str.indexOf(";)") != -1) {
int index = str.indexOf(";)");
bfr.replace(index,index+2,"<IMG SRC=\""+WINK +"\">");
str= bfr.toString();
}
while(str.indexOf(";-)") != -1) {
int index = str.indexOf(";-)");
bfr.replace(index,index+3,"<IMG SRC=\""+WINK +"\">");
str= bfr.toString();
}
while(str.indexOf(":x") != -1) {
int index = str.indexOf(":x");
bfr.replace(index,index+2,"<IMG SRC=\""+LOVE +"\">");
str= bfr.toString();
}
while(str.indexOf(":-x") != -1) {
int index = str.indexOf(":-x");
bfr.replace(index,index+3,"<IMG SRC=\""+LOVE +"\">");
str= bfr.toString();
}
By using above code i tried to replace string wid images....but it is nt working.....
plz help.......Thanks
Actually i m using a Chat Constant interface for calling all these images......
here is that Chat constant file......
public interface ChatConstants
{
//final String SERVER_HOST = "127.0.0.1";
//final intSERVER_PORT = 2979;
//final int BACKLOG= 10;
//final int MAX_MESSAGE_SIZE= 2048;
//
////Message constants
//final int CLIENT_LOGIN = 1;
//final int CLIENT_LOGOUT = 2;
//final int PUBLIC_CHAT= 3;
//final int PRIVATE_CHAT= 4;
//final int SERVER_DOWN= 5;
//final int USERS_LIST= 6;
//final int CHANGE_STATUS= 7;
//final int CONFERENCE_CREATE = 8;
//final int CONFERENCE_INVITE = 9;
//final int CONFERENCE_JOIN= 10;
//final int CONFERENCE_DENY= 11;
//final int CONFERENCE_LEAVE = 12;
//final int CONFERENCE_LIST= 13;
//User status
final int ONLINE= 1;
final int OFFLINE= 2;
final int BUSY= 3;
final int IDLE= 4;
//Look and feel
final String WINDOWS ="com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
final String METAL="javax.swing.plaf.metal.MetalLookAndFeel";
final String MOTIF= "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
//Smileys
final String SMILE = ClassLoader.getSystemClassLoader().getResource("images/1.gif").toString();
final String SAD = ClassLoader.getSystemClassLoader().getResource("images/2.gif").toString();
final String WINK = ClassLoader.getSystemClassLoader().getResource("images/3.gif").toString();
final String SHY = ClassLoader.getSystemClassLoader().getResource("images/4.gif").toString();
final String LOVE = ClassLoader.getSystemClassLoader().getResource("images/5.gif").toString();
final String TEETH = ClassLoader.getSystemClassLoader().getResource("images/6.gif").toString();
final String QUESTION = ClassLoader.getSystemClassLoader().getResource("images/7.gif").toString();
final String BYE = ClassLoader.getSystemClassLoader().getResource("images/8.gif").toString();
final String TONGUE = ClassLoader.getSystemClassLoader().getResource("images/9.gif").toString();
final String KISS = ClassLoader.getSystemClassLoader().getResource("images/10.gif").toString();
final String SURPRISE = ClassLoader.getSystemClassLoader().getResource("images/11.gif").toString();
final String ANGRY = ClassLoader.getSystemClassLoader().getResource("images/12.gif").toString();
final String MEAN = ClassLoader.getSystemClassLoader().getResource("images/13.gif").toString();
final String COOL = ClassLoader.getSystemClassLoader().getResource("images/14.gif").toString();
final String DEVIL = ClassLoader.getSystemClassLoader().getResource("images/16.gif").toString();
final String CRY = ClassLoader.getSystemClassLoader().getResource("images/17.gif").toString();
final String LAUGH = ClassLoader.getSystemClassLoader().getResource("images/18.gif").toString();
final String EQUISMILE = ClassLoader.getSystemClassLoader().getResource("images/19.gif").toString();
final String COFFEE = ClassLoader.getSystemClassLoader().getResource("images/20.gif").toString();
}
and i m calling this to my last code........