Server Help

ASSS Custom Projects - <java> UChat

BDwinsAlt - Fri Dec 21, 2007 8:50 pm
Post subject: <java> UChat

I have been working on a chat client. I know there are already some out there. I felt like making one tongue.gif

Does anybody know of any way to easily change the color of text on the screen? The screen shot should clear up any questions. Right now I'm using a TextArea. I thought I read that the text color could only be changed to one color. I want to be able to change the colors depending on if it's a Private message, chat message, public message, or team message.

Also, I need to find a better user's online thing at the far right. Right now it is also a textarea (Uneditable). I need something that will allow me to select different names so someone can just type "/" instead of ":name:" each time.

Lastly, I need a way to edit the textfield where the chat is typed. I need to make it edit itself when :: is typed to display :name:. Right now it only displays :name: after someone hits enter. This could be confusing.

Any ideas? I've already got most of the stuff done. Also, is a hashtable the best thing to use for online user management? I'm using a hashtable to put and remove people from the list, then reloading the list.

Thanks.

P.S. Once this is done, I will finish it up by making the mobile edition. Dr Brain can be in Hyperspace on his cell biggrin.gif
Dr Brain - Fri Dec 21, 2007 9:47 pm
Post subject:
You could always take a look at the ChatNut Applet source. I'm sure there's a link to it somewhere, or I could upload it if you can't find one. I already solved all those UI issues in it. I don't recall the exact manner though.
Bak - Sat Dec 22, 2007 12:20 am
Post subject:
i know in some components you can embed html tags
BDwinsAlt - Sat Dec 22, 2007 6:15 am
Post subject:
I read that, too. I know TextAreas won't use html tags. There was something about JComponent, but I never found much about it. I'll look at the ChatNut source when I get home from work today.

Edit: I got the color working. I'm using a JTextPane. Now all I have to do is: append(Color c, String str);

Now I need to figure out the whole select player thing.

For future reference:
Code: Show/Hide

public static JTextPane chatText = null;

...

chatText = new JTextPane();

...

     public static void append(Color c, String s) {
       StyleContext sc = StyleContext.getDefaultStyleContext();
       AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,
                                           StyleConstants.Foreground, c);
    
       int len = chatText.getDocument().getLength(); // same value as getText().length();
       chatText.setCaretPosition(len);  // place caret at the end (with no selection)
       chatText.setCharacterAttributes(aset, false);
      chatText.setEditable(true); // Won't print text unless it's enabled
       chatText.replaceSelection(s); // Adds the new line (with Color)
      chatText.setEditable(false); // Disable so you can't backspace chat.
     }


Smong - Wed Dec 26, 2007 5:39 pm
Post subject:
I think you can figure out the player list (the hint is in the name).

For tracking when text is typed you could use a DocumentListener and the insertUpdate() callback. Naap's chat tab uses something like:
Code: Show/Hide
JTextArea inputarea;
...
myeventhandler = new EventHandler();
inputarea.getDocument().addDocumentListener(myeventhandler);
...
class EventHandler implements DocumentListener
{
   public void insertUpdate(DocumentEvent evt)
   {
...

BDwinsAlt - Wed Dec 26, 2007 5:51 pm
Post subject:
Thanks. Now I know what to do. I had no idea what to search to find it. I'll take a look at NAAP to see if I missed anything with my client.
BDwinsAlt - Thu Dec 27, 2007 4:00 pm
Post subject:
New problem. I can get it to recognize what I type and append a message when I type something, but I can't edit the actually textfield where the chat is typed. I tried setting editable to false, but no luck.

FIXED: I had to modify it outside of the document listener. I have to remove the DocumentListener then re-add it after I use setText.

Nasty hack :X
Bak - Fri Dec 28, 2007 9:47 am
Post subject:
I always use http://java.sun.com/docs/books/tutorial/ui/features/components.html when i'm looking for components...

did you try setting editable to true? (if it's editable it can be edited... can be changed)
BDwinsAlt - Fri Dec 28, 2007 7:43 pm
Post subject:
First thing I tried.

Internet was out all day, sorry. For some reason my Mac ID on my modem was removed from the account. Charter makes me sick.
Smong - Sun Dec 30, 2007 4:08 pm
Post subject:
BDwinsAlt wrote:
I had to modify it outside of the document listener.
That might be because you're not supposed to modify gui stuff outside of the gui thread. To run something inside the gui thread you can use SwingUtilities.invokeLater().

The setEditable stuff is probably only for user functionality, for example graying out the text area and not allowing the user to type into it. I doubt it has anything to do with the setText function.
BDwinsAlt - Mon Dec 31, 2007 1:55 pm
Post subject:
I don't really know what else to add. I want it to stand out from the rest of the clients. I don't expect anyone to really use it. It helps me learn at least.

Here is what it looks like now. As far as GUI goes, there is color, player select, and menus.

For some reason it took off the title bar thing and the border around it when I screenshotted only the window.

k0zy - Mon Dec 31, 2007 3:24 pm
Post subject:
Does it connect to multiple zones at once?
EDIT: That even possible when zones use the same biller?
BDwinsAlt - Mon Dec 31, 2007 3:36 pm
Post subject:
It is possible. You just can't be in the same zone at once. It would be cool to have tabs in different zones. Then again, there aren't many asss zones.
k0zy - Mon Dec 31, 2007 4:28 pm
Post subject:
But it would make you stand out form the rest...
Besides, handling multiple socket connections can be quite interesting. For a server at least...
Animate Dreams - Mon Dec 31, 2007 8:25 pm
Post subject:
If you REALLY wanted to stand out, you could use your code to write a tutorial on chatnet clients.
CypherJF - Mon Dec 31, 2007 8:37 pm
Post subject:
Just to let you know my biller will kick off other user sessions so only 1 player id can be logged in at once.
Animate Dreams - Tue Jan 01, 2008 1:15 am
Post subject:
That makes me sad, Cypher. =\
CypherJF - Tue Jan 01, 2008 2:18 am
Post subject:
Best thing to add is a way to determine if a zone is online or not; sortable user list (by freq, ship, user name, pid (?))...
Smong - Fri Jan 04, 2008 7:45 pm
Post subject:
What about writing a module that can send the news.txt to the chat client somehow. Or even better, a link to a website that gets loaded in part of the window, that way you can have more control over the layout of the news.txt.
Animate Dreams - Mon Jan 07, 2008 8:17 pm
Post subject:
Smong wrote:
What about writing a module that can send the news.txt to the chat client somehow. Or even better, a link to a website that gets loaded in part of the window, that way you can have more control over the layout of the news.txt.


Too many people uses .rtfs for their news.txt.
Mine GO BOOM - Mon Jan 07, 2008 8:31 pm
Post subject:
Animate Dreams wrote:
Too many people uses .rtfs for their news.txt.

If designed correctly, can have mostly plain text up front that is invisible in the richtext box, for Win9x users. They'll see a bit of random junk up top, and a whole bunch on the bottom.

Personally, I'm a plaintext kind of guy.
AJ - Thu Jan 17, 2008 10:30 pm
Post subject:
Thats pretty cool BDwinsalt i wish i could code like that xD.
BDwinsAlt - Thu Jan 17, 2008 10:41 pm
Post subject:
You have to start somewhere. Just google some examples. I learned by downloading simple code and editing it to see what it would do. TWCore helped me a lot. At first my code was functional, but a lot of things were done the wrong way.

Try some java. I used http://javaalmanac.com for a quick reference.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group