Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done with Documentation in all java Files #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 47 additions & 34 deletions src/ChatClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import javax.swing.ScrollPaneConstants;


// CLASS: ChatClient
public class ChatClient
{
/**
* Class for chat client.
*/
public class ChatClient {

JTextArea incoming;
JTextField outgoing;
Expand All @@ -30,18 +31,21 @@ public class ChatClient
String username;
String[] ps;


// FUNCTION: main
public static void main(String[] args)
{
/**
* main Function.
*
* @param args The arguments
*/
public static void main(String[] args) {
ChatClient client = new ChatClient();
client.go();
}


// FUNCTION: go
public void go()
{
/**
* go function.
*/
public void go() {

JFrame frame = new JFrame("Client");
JPanel mainPanel = new JPanel();
Expand All @@ -64,7 +68,7 @@ public void go()
userList.setLineWrap(true);
userList.setWrapStyleWord(true);
userList.setEditable(false);

JScrollPane uScroller = new JScrollPane(userList);
uScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

Expand Down Expand Up @@ -94,13 +98,12 @@ public void go()

}

/**
* function for setting up Networking.
*/
private void setUpNetworking() {

// FUNCTION: setUpNetworking
private void setUpNetworking()
{

try
{
try {
sock = new Socket(Constants.HOST, Constants.PORT);

InputStreamReader streamReader = new InputStreamReader(sock.getInputStream());
Expand All @@ -110,37 +113,41 @@ private void setUpNetworking()

System.out.println("Networking established");

}
catch(IOException ex)
{
} catch (IOException ex) {
ex.printStackTrace();
}
}

// CLASS: SendButtonListener
public class SendButtonListener implements ActionListener
{
/**
* Class for send button listener.
* implementing the ActionListener
*/
public class SendButtonListener implements ActionListener {


// FUNCTION: actionPerformed
public void actionPerformed(ActionEvent ev)
{
try
{
/**
* function for actionPerformed.
*
* @param ev is an Object of type ActionEvent.
*/
public void actionPerformed(ActionEvent ev) {
try {
writer.println(username + " : " + outgoing.getText());
writer.flush();
}
catch(Exception ex)
{
} catch (Exception ex) {
ex.printStackTrace();
}
outgoing.setText("");
outgoing.requestFocus();
}
}

/**
* Class for incoming reader.
*/
public class IncomingReader implements Runnable {

/**
* function for run.
*/
public void run() {
String message;

Expand All @@ -163,7 +170,13 @@ public void run() {
e.printStackTrace();
}
}

/**
* function for messageOrList
*
* @param ms of type ms
*
* @return true or false.
*/
public boolean messageOrList(String ms) {
ps = ms.split(Constants.REG_EX_ESC_PATTERN);
return Constants.SHOW_MSG_VAL_CON_VAL.equals(ps[0]);
Expand Down
Binary file modified src/ChatServer$ClientHandler.class
Binary file not shown.
Binary file modified src/ChatServer$SendButtonListener.class
Binary file not shown.
Binary file modified src/ChatServer.class
Binary file not shown.
53 changes: 42 additions & 11 deletions src/ChatServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;


/**
* Class for chat server.
*/
public class ChatServer {

JTextArea clientsMessage;
Expand All @@ -27,12 +29,18 @@ public class ChatServer {
JTextField smsToAll;
ArrayList<String> uname = new ArrayList<String>();
ArrayList<Socket> port = new ArrayList<Socket>();

/**
* Class for client handler.
*/
public class ClientHandler implements Runnable {

BufferedReader reader;
Socket sock;

/**
* Constructs the object.
*
* @param clientSocket The client socket
*/
public ClientHandler(Socket clientSocket) {

try {
Expand All @@ -45,7 +53,9 @@ public ClientHandler(Socket clientSocket) {
}
}


/**
* run function.
*/
public void run() {

String message;
Expand Down Expand Up @@ -85,11 +95,17 @@ public void run() {
}
}

// CLASS: SendButtonListener
/**
* Class for send button listener.
*/
public class SendButtonListener implements ActionListener
{

// FUNCTION: actionPerformed
/**
* function for action Performed.
*
* @param arg0 The argument 0
*/
@Override
public void actionPerformed(ActionEvent arg0)
{
Expand All @@ -101,7 +117,9 @@ public void actionPerformed(ActionEvent arg0)
}

}

/**
* function for showing clients.
*/
public void showingClients() {
String st = Constants.SHOW_MSG_VAL_CON_VAL;
String t = Constants.EMPTY;
Expand Down Expand Up @@ -131,7 +149,9 @@ public void showingClients() {
}


// FUNCTION: go
/**
* function for go.
*/
public void go()
{
clientOutputStreams = new ArrayList();
Expand Down Expand Up @@ -162,7 +182,11 @@ public void go()
}


// FUNCTION: tellEveryOne
/**
* function to tell EveryOne.
*
* @param message The message
*/
public void tellEveryone(String message)
{

Expand All @@ -183,7 +207,10 @@ public void tellEveryone(String message)
}
}

// FUNCTION: addAction
/**
* Adds an action.
*/

public void addAction()
{
JFrame window = new JFrame("SERVER");
Expand Down Expand Up @@ -223,7 +250,11 @@ public void addAction()
clientsMessage.setText(Constants.EMPTY);

}

/**
* function for main.
*
* @param args The arguments
*/
public static void main(String[] args) {
ChatServer cs = new ChatServer();
cs.addAction();
Expand Down
Binary file added src/Constants.class
Binary file not shown.
14 changes: 14 additions & 0 deletions src/Constants.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
/**
* Class for constants.
* This class contains all the constants that are used
* in program
*/
public class Constants {
/**
* Constructs the object.
*/
private Constants() {
/**
* unused Constructor
*/
}

public static final String CLIENT = "Client";
public static final String SEND = "Send";
public static final String MESSAGE_BOX = "Message Box";
Expand Down
Loading