Click here to Skip to main content
15,888,286 members
Articles / Programming Languages / Java / Java SE

Java Chat With Customizable GUI

Rate me:
Please Sign up or sign in to vote.
4.75/5 (105 votes)
7 May 2007CPOL3 min read 1.2M   63.3K   134  
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
package com.jeeva.chatclient;

import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import java.awt.Panel;
import java.awt.Button;
import java.awt.Label;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
public class MessageBox extends Dialog implements ActionListener,CommonSettings 
{  
	MessageBox(ChatClient Parent,boolean okcan)
	{
	   super(Parent, "Information", false);
	   chatclient = Parent;
	   setBackground(chatclient.ColorMap[0]);
	   setLayout(new BorderLayout());	 
	   setFont(chatclient.getFont());  
	   messagecanvas = new MessageCanvas(chatclient);
	   MessageScrollView = new ScrollView(messagecanvas,true,true,200,100,0);
	   messagecanvas.scrollview = MessageScrollView;
	   messagecanvas.setBackground(chatclient.ColorMap[0]);	   	
	   add("Center",MessageScrollView);	   	   
	   addOKCancelPanel(okcan);
	   createFrame();	  
	   pack();
	   setVisible(true);
	   setSize(200,160);
	   setResizable(false);
	}
	
	protected void AddMessage(String message)
	{	
		messagecanvas.AddMessageToMessageObject(message,MESSAGE_TYPE_JOIN);		
	}
	
   	private void addOKCancelPanel( boolean okcan ) 
  	{
	  Panel panel = new Panel();
   	  panel.setLayout(new FlowLayout());
   	  createOKButton( panel);
   	  if (okcan == true)
      	createCancelButton( panel );
   	  add("South",panel);
   	}

  private void createOKButton(Panel panel) 
  {
   	CmdOk = new CustomButton(chatclient,"OK");   	
   	panel.add(CmdOk);
   	CmdOk.addActionListener(this); 
  }

  private void createCancelButton(Panel panel) 
  {
   	CmdCancel = new CustomButton(chatclient,"Cancel");
   	panel.add(CmdCancel);
   	CmdCancel.addActionListener(this);
  }

  private void createFrame() 
  {
   	Dimension dimension = getToolkit().getScreenSize();
   	setLocation(dimension.width/3,dimension.height/3);
  }

  public void actionPerformed(ActionEvent ae)
  {
   if(ae.getSource() == CmdOk) 
   {     
     dispose();
   }
   else if(ae.getSource() == CmdCancel) 
   {
     dispose();
   }
  }
   
   /***********Global Variable Declarations **************/
   ChatClient chatclient;
   Button CmdOk, CmdCancel;
   MessageCanvas messagecanvas;
   ScrollView MessageScrollView;
 }

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Architect
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions