Click here to Skip to main content
13,798,662 members
Click here to Skip to main content
Add your own
alternative version


133 bookmarked
Posted 14 Jun 2002
Licenced CPOL

Java Chat With Customizable GUI

, 7 May 2007
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

You may also be interested in...

Comments and Discussions

Generalunable 2 download Pin
pvasu31-Jul-03 4:48
memberpvasu31-Jul-03 4:48 
GeneralRe: give me source code of chat server Pin
Anonymous7-Sep-04 22:04
memberAnonymous7-Sep-04 22:04 
GeneralRe: give me source code of chat server Pin
Anonymous7-Sep-04 22:05
memberAnonymous7-Sep-04 22:05 
GeneralAbout Downloading of &quot;Java Chat With Customizable GUI&quot; Pin
gagan jain1-Jul-03 22:11
membergagan jain1-Jul-03 22:11 
GeneralJTextPane Pin
popeye2128-Jun-03 10:26
memberpopeye2128-Jun-03 10:26 
QuestionWat about file transfer? Pin
appleworm_8126-Jun-03 9:17
memberappleworm_8126-Jun-03 9:17 
AnswerRe: Wat about file transfer? Pin
Jeeva S26-Jun-03 19:29
memberJeeva S26-Jun-03 19:29 
QuestionCan you help me? Pin
hong phuoc15-Jun-03 16:58
memberhong phuoc15-Jun-03 16:58 
Questionhow to install your chat Pin
koni70020-May-03 9:05
susskoni70020-May-03 9:05 
GeneralProblem in sending private message Pin
asdfasfsafdasdf17-Apr-03 3:38
memberasdfasfsafdasdf17-Apr-03 3:38 
GeneralSolution For Ur Problem (Jeeva) Pin
Jeeva S20-Apr-03 19:16
memberJeeva S20-Apr-03 19:16 
Jeeva S15-Apr-03 3:18
memberJeeva S15-Apr-03 3:18 
GeneralHi,Jeeva S: New Stars On Java World. Pin
sek8588@hotmail.com5-Mar-03 22:20
membersek8588@hotmail.com5-Mar-03 22:20 
GeneralRe: Hi,Jeeva S: New Stars On Java World. Pin
Member 2949754-Apr-03 23:43
memberMember 2949754-Apr-03 23:43 
please i need data flow diagram because i am doing the same projectRoll eyes | :rolleyes:

ramesha g k
GeneralWhow Pin
ScriptBreaker5-Dec-02 3:16
memberScriptBreaker5-Dec-02 3:16 
GeneralRe: Whow Pin
Jeeva S5-Dec-02 5:46
memberJeeva S5-Dec-02 5:46 
GeneralRe: Whow Pin
Jeeva S5-Dec-02 5:48
memberJeeva S5-Dec-02 5:48 
Generalchatserver Pin
chaudry saif ullah7-Dec-02 8:22
memberchaudry saif ullah7-Dec-02 8:22 
GeneralRe: Whow Pin
Member 29497521-Mar-03 19:02
memberMember 29497521-Mar-03 19:02 
GeneralRe: Whow Pin
Member 29497523-Mar-03 18:40
memberMember 29497523-Mar-03 18:40 
QuestionWhere is it the code? Pin
Jairo Andres3-Dec-02 6:29
memberJairo Andres3-Dec-02 6:29 
GeneralGood but... Pin
NormDroid3-Oct-02 7:14
professionalNormDroid3-Oct-02 7:14 
GeneralI Have Updated article as per ur request Pin
Jeeva S4-Oct-02 23:11
memberJeeva S4-Oct-02 23:11 
GeneralI have updated the source code Pin
Jeeva S2-Oct-02 19:30
memberJeeva S2-Oct-02 19:30 
GeneralRe: I have updated the source code Pin
bpham4-Dec-02 20:45
memberbpham4-Dec-02 20:45 

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

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

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.181207.3 | Last Updated 8 May 2007
Article Copyright 2002 by Jeeva S
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid