Sie sind auf Seite 1von 5

User Documentation

-Title Page
Chat Client
Developed by Avick Saha
-Introduction
This is the GUI interface for a chat client terminal & this is a user friendly java
application. Through this window a client can interact with other people and type text. Even user
list is displayed for easy selection.
Bibliography
Internal Documentation::
-What is Name of the Project or Component..
Chat Client
-Who wrote this project..
Avick Saha
-where does the Component fit in the general System design..
This java application is the client side for the chat application. It requires server side to
interact.

-What Technology is used..


This application uses total java technology. It also uses java swing and java event model
to add events. Swing is used to give unique look and feel.
-Why the component Exist.
-How the Components used and Controls.
This application uses a text box to write a message and after pressing enter it submits the
message to the main text panel, from where people can see it. The main panel also displays the
user name along with the message. There are also a option for different user to select their
names.
Program Comments:

-MODULE FUNCTIONALITY
There are five class involved in this project.
1) ChatClient
This is the main class for the project. It contains the rest of the classes.
2) SendHandler
This class is used to handle event when a client types and press enter, the text will be shifted
to the main text panel.
3) CloseHandler
Used to handle the event to close the main project window.
4) AboutHandler

Mainly event class to handle the dialog box

5) AboutDialog

This clas inherits JDialog class to create a Dialog box.

-PARAMETERS AND THEIR PURPOSE

source code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ChatClient
{
private JTextArea output;
private JTextField input;
private JButton sendButton;
private JButton quitButton;
private JComboBox usernames;
private JScrollPane textPane;
private JDialog aboutDialog;
JFrame frame;
public ChatClient()
{
output = new JTextArea(10,50);
input = new JTextField(50);
sendButton =new JButton("Send");
quitButton = new JButton("Quit");
usernames = new JComboBox();

usernames.addItem("Jane Doe");
usernames.addItem("1337dud3");
usernames.addItem("Java Geek");
textPane = new
JScrollPane(output,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
}
public void launchFrame(){
JFrame frame = new JFrame("Chat Room");
frame.setLayout(new BorderLayout());
frame.add(input,BorderLayout.SOUTH);
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(3,1));
p1.add(sendButton);
p1.add(quitButton);
p1.add(usernames);
frame.add(p1,BorderLayout.CENTER);
sendButton.addActionListener(new SendHandler());
frame.addWindowListener(new CloseHandler());
quitButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
frame.add(textPane,BorderLayout.WEST);
JMenuBar mb = new JMenuBar();
JMenu file = new JMenu("File");
JMenuItem quitMenuItem = new JMenuItem("Quit");
quitMenuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});

JMenu help = new JMenu("Help");


JMenuItem aboutMenuItem = new JMenuItem("About");
aboutMenuItem.addActionListener(new AboutHandler());
help.add(aboutMenuItem);
mb.add(help);
file.add(quitMenuItem);
mb.add(file);
frame.setJMenuBar(mb);
frame.pack();
frame.setVisible(true);
}
public static void main(String args[])
{
ChatClient c = new ChatClient();
c.launchFrame();
}
private class SendHandler implements ActionListener{
//output.setCaretPosition(output.getDocument().getLength()-1);
public void actionPerformed(ActionEvent e){
String text = input.getText();
output.append(usernames.getSelectedItem()+" : "+text+"\n");
input.setText("");
}
}
private class CloseHandler extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
private class AboutHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
if(aboutDialog == null){

aboutDialog = new AboutDialog(frame,"About",true);


}
aboutDialog.setVisible(true);
}
}
private class AboutDialog extends JDialog implements ActionListener
{
public AboutDialog(Frame parent,String title,boolean modal){
super(parent,title,modal);
add(new JLabel("The ChatClient is a neat tool that allows you to
talk to other ChatClients via a ChatServer"),BorderLayout.NORTH);
JButton b = new JButton("OK");
add(b,BorderLayout.SOUTH);
b.addActionListener(this);
pack();
}
public void actionPerformed(ActionEvent e){
setVisible(false);
}
}
}

Das könnte Ihnen auch gefallen