Java JTextPane and String Tokens -> Images

imported_Ned Flanders

Senior member
May 11, 2005
641
0
0
Greetings.

This is regarding a chat program I am making.
So far it is a pretty standard program:

JTextPane to make message (inc smilies), which is transferred to all clients in the form of a String - : ) = Smiley face etc.

The problem is displaying it over at the other end.
The only way I can see this being done is splitting the message at ever ":" and checking the character after to see if it is a valid smiley code. But I am having problems dealing with if a user just entered a : or :nkjfgfg etc.

Is there a better way I can do this - Or will I just have to code some extensive logic to decide what to display. Is there no way to append a styed document to a JTextPane?

I hope I have made my problem clear.
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
It seems pretty logical to traverse through the string and search for the colons

If the smilies are only 2 characters, for example ;P, I don't see why you can't do something like, assuming you make all of the types match

c = charAt(returnedIndexOfColon + 1)
string smilie = stringChat.charAt(returnedIndexOfColon).toString() + c.toString()
if smilie.equals(";P")
...

You get the idea.
 

Atheus

Diamond Member
Jun 7, 2005
7,313
2
0
Could make a text file of smileys and filenames like

:) = smile.gif
;) = wink.gif

and then parse this into an array on startup. You can just search the messages for anything in the array, and if you want to add any, you can add them to the text file.

/Edit: oops, AT parsed my smileys, but you get the idea...
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
Originally posted by: Atheus
Could make a text file of smileys and filenames like

:) = smile.gif
;) = wink.gif

and then parse this into an array on startup. You can just search the messages for anything in the array, and if you want to add any, you can add them to the text file.

/Edit: oops, AT parsed my smileys, but you get the idea...

That's a good idea as well. :thumbsup: