Click here to Skip to main content
11,411,840 members (51,863 online)
Click here to Skip to main content

Java Chat With Customizable GUI

, 7 May 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
A complete Java (AWT) Chat Application with great customizable GUI Interface. It has features such as general chat and private chat, music when message arrives, sending images and more
Sample Image - chat.jpg

Note: The latest source code has been uploaded along with this article now.


This is my second article on The Code Project. I have already posted Tap Control in Java here.

This Java Chat is purely AWT based, no Swing Components used and still it has a great look and feel. For this application, I have developed my own Tab Control and Image Canvas. Also, I have uploaded the complete source code here. You can download it from there.

This is the updated article . Now I have posted all the concepts behind the chat instead
of putting the source code as per the request of The Code Project members.


  1. Transfer Smilies with Text
  2. Private Chat
  3. Great Look and Feel with Customized Color
  4. Audio Enabled


In this Chat application, we have both server side and client side modules.. In server side, I have defined our own RFC Commands. Some of the commands which I have used in this application are listed below:

  • HELO - Initialize connection to server
  • QUIT - Remove users from chat
  • KICK - Kickoff from chat
  • CHRO - Change room
  • MESS - Send general message
  • PRIV - Send private message
  • ROCO - Get users count in specified room
  • CALL - Request for voice chat (not included with this one)

Server Side Module

I will briefly explain the concepts behind the server side.

  • Created custom UserObject class which will have the client details like username, the socket of user, and the room name, etc.
  • When the Chat Server runs, it opens the Server Socket at port 1436 (we can modify too) and listen for the client to connect. If the client connects to the server, it will open a separate thread to service. So, when the client sends QUIT command, it will close the thread too. If you take a look, you will get all the details.

This is a sample code of getting connection from the Chat Client and creating a new object of ChatCommunication. In ChatCommunication class, we will create a thread to watch all the commands from the client and responds to the client too.
    Socket socket = serversocket.accept();
    ChatCommunication chat = new ChatCommunication(socket);

ChatCommuncation(Socket socket)
    personalsocket = socket;
    dout = new Dataoutputstream(personalsocket.getoutoutstream());

Client Side Module

I will also briefly explains the concepts behind the Client side Chat.

  • When the Chat Client runs, it will open a socket and connect to ChatServer by sending HELO RFC to Server.. Once it gets connected, the chat client will keep the socket connection and communicate with the server whenever the user commands it.
  • Another important thing in the client module is the USER INTERFACE. I have created my OWN Custom Components like Tab Control and Image Supported Message Canvas.
  • The basic idea of creating a message canvas is based on simple logic. Whenever users enter the message, I will store it in arraylist. Also, in the Arraylist, I keep the XOffset and YOffSet position of each message. If you have a look of this sample code, you might get an idea of what I mean.
for(int i =0; i < messagearraylist.size();i++)

This is the Function To Paint Images and Text Messages
private void PaintMessageIntoCanvas(MessageObject messageObject)
int m_YPos = messageobject.StartY - YOffset;
int m_XPos = 5 - XOffset;
int CustomWidth = 0;
String Message = messageobject.Message;

/*************Print The User Name in UserName Font **************/        
if(Message.indexOf(":") >= 0)
fontmetrics = chatclient.getGraphics().getFontMetrics();
String m_UserName = Message.substring(0,Message.indexOf(":")+1);
Message = Message.substring(Message.indexOf(":")+1);

/*********Set the Text Font **********/
fontmetrics =  chatclient.getGraphics().getFontMetrics();

/**********Print Image Area********/
if(messageobject.IsImage == true)
tokenizer = new StringTokenizer(Message," ");    
TokenString = tokenizer.nextToken();                
if(TokenString.indexOf("~~") >= 0)
/********If its a Proper Image*************/
try {
int m_ImageIndex = Integer.parseInt(TokenString.substring(2));
if((m_ImageIndex >= 0) && (m_ImageIndex < chatclient.IconCount))
,m_XPos+CustomWidth,m_YPos - 15,messageobject.Width,messageobject.Height,this);
}catch(Exception _Exc) { }                
if(TotalWidth < m_XPos+CustomWidth)
TotalWidth = m_XPos+CustomWidth;


In this updated article, I have uploaded my complete source code. To download the full source code, click here.

If you still have any doubts, feel free to contact me at


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Jeeva S
United States United States
No Biography provided

Comments and Discussions

QuestionError Connect to chat PinmemberGronscij20-Apr-15 22:54 
Questionregarding gui in netbeans PinmemberMember 1149954712-Mar-15 0:17 
Questionone server to multiple clients PinmemberMember 1068127321-Oct-14 21:44 
Questionproblem in adding emoticons PinmemberMember 1095065722-Jul-14 22:25 
QuestionJava Chat With Customizable GUI PinmemberMember 1081012719-Jul-14 23:18 
Questionlogin values PinmemberMember 1063133727-Feb-14 23:56 
Questionsay th'k PinmemberNohara Shinnosuke12-Nov-13 9:28 
QuestionRooms PinmemberMember 1028705320-Sep-13 11:13 
QuestionA link to the correct source code please! PinprofessionalArash black14-Aug-13 23:46 
GeneralThanks PinmemberPhieTheKId31-May-13 20:31 
QuestionRegarding proxy server or port Pinmemberdeepali.gudulkar27-May-13 2:59 
QuestionHow to use this chat application PinmemberMember 1000093620-Apr-13 3:34 
Questionis this messenger even applicable on linux? Pinmemberankur0124-Apr-13 20:21 
QuestionU r awesome PinmemberIsank Agarwal11-Mar-13 8:36 
Questionregarding this chat application PinmemberMember 98457264-Mar-13 6:55 
AnswerRe: regarding this chat application PinmemberIsank Agarwal11-Mar-13 8:38 
Questionhow to run the soure code in netbeans Pinmembermaheshkadtan29-Nov-12 8:15 
Questionproblem in running code Pinmemberamruta023-Oct-12 4:08 
AnswerRe: problem in running code PinmemberIsank Agarwal11-Mar-13 10:08 
Questiontanx a lot anna PinmemberDanish Rogy28-Sep-12 23:44 
QuestionTried to run this but am getting always server closed information . Pinmembersanket.patil314-Sep-12 0:15 
QuestionHow does it work? PinmemberAzJay16-Jul-12 1:19 
QuestionHi guys new to JAVA world Pinmemberzainfarooq7-Jun-12 11:45 
Dear All freinds Hi i am new to Java and i need to create a chat application in Java can you guys help me with it..... i am confused regarding switch concept..... any one can give example so i can understand....thanks.....zain
GeneralMy vote of 5 Pinmemberdamai00726-Apr-12 18:48 
QuestionProgram PinmemberMember 861459122-Apr-12 17:04 
QuestionGUI Question Pinmemberabhishekganguly199017-Apr-12 5:45 
Questiondocumentation Pinmemberkriti joshi11-Apr-12 6:23 
GeneralMy vote of 5 Pinmemberswdev.bali19-Mar-12 21:57 
QuestionGreat Thanks! Pinmemberswdev.bali19-Mar-12 21:57 
NewsPeer to peer PinmemberRamyaGovindan26-Feb-12 1:58 
QuestionNeed your Assistance PinmemberNiraj Deshmukh12313-Nov-11 23:23 
QuestionDocumentation Pinmemberdamustk16-Oct-11 13:56 
Generali want mini project PinmemberAttaullah bablu2-Oct-11 5:09 
Questionhai jeeva PinmemberMember 82189447-Sep-11 3:19 
Questionplz help Pinmembergomathipriya31-Aug-11 22:03 
QuestionHow to use this chat application... PinmemberMember 819031125-Aug-11 22:27 
Generalrequest Pinmemberpooja yadav b18-Aug-11 2:07 
Questionregarding the problem i am facing in this chat server.. PinmemberMember 801105314-Jul-11 21:13 
GeneralNice Project. I made one too but not with that much features :P PinmemberHarish_80809-Jun-11 11:25 
GeneralRe: Nice Project. I made one too but not with that much features :P PinmemberKag-Maniac4-Nov-11 2:16 
Generalabout the projcet Pinmembermani432120-Apr-11 9:48 
GeneralMy vote of 5 Pinmemberprakashrai83814-Apr-11 10:42 
Generaldocumentation Pinmemberfmalique8811-Apr-11 18:08 
Generaldocumentation PinmemberMember 77928674-Apr-11 8:57 
Generalhelpp!!! PinmemberMember 77928674-Apr-11 8:55 
GeneralRe: helpp!!! Pinmembergomathipriya31-Aug-11 22:11 
GeneralAppreciate PinmemberAmit Trivedi 282015-Feb-11 16:06 
GeneralMy vote of 5 PinmemberAmit Trivedi 282015-Feb-11 16:04 
Generalserver Pinmemberadeebshahi13-Feb-11 5:14 
GeneralRe: server PinmemberMember 77928674-Apr-11 8:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150414.5 | Last Updated 8 May 2007
Article Copyright 2002 by Jeeva S
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid