• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java JTextPane and String Tokens -> Images

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.
 
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.
 
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...
 
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:
 
Back
Top