Can anyone make UML diagram for me? I’am a newbie…I want to cross refrence with my own UML diagram.
This code is a simple Java Client Chat Apps.
Thanks
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package tcpchat;
import javax.swing.;
import java.awt.event.;
import java.io.;
import java.net.;
import java.util.*;
public class TCPServerUI {
private static JButton inSendButton = new JButton(“Send”);
private static JButton connectButton = new JButton(“Connect”);
private static JButton disconnectButton = new JButton(“Disconnect”);
private static JTextField sendText = new JTextField("", 23);
private static JTextArea ta = new JTextArea("", 15, 30);
private static ObjectInputStream inFromClient;
private static ObjectOutputStream outToClient;
private static Socket connected;
private static ServerSocket Server;
private static boolean socketReady;
static class sendButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String toclient = sendText.getText();
ta.append("server> " + toclient + ‘\n’);
if ( toclient.equals ("q") || toclient.equals("Q") )
{
try{
outToClient.writeObject(toclient);
connected.close();
} catch (IOException e2){
ta.append(e2.getMessage());
}
}
else
{
try{
outToClient.writeObject(toclient);
} catch (IOException e3){
ta.append(e3.getMessage());
}
}
sendText.setText("");
}
}
private static sendButtonListener sendButtonE = new sendButtonListener();
public static void guiInit() {
JFrame f = new JFrame(“Server Chat Form”);
JPanel upperPanel = new JPanel();
JPanel lowerPanel = new JPanel();
JPanel connectionPanel = new JPanel();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
inSendButton.addActionListener(sendButtonE);
f.getContentPane().add(connectionPanel, "North");
f.getContentPane().add(upperPanel, "Center");
f.getContentPane().add(lowerPanel, "South");
connectionPanel.add(connectButton);
connectionPanel.add(disconnectButton);
upperPanel.add(sendText);
upperPanel.add(inSendButton);
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
lowerPanel.add(new JScrollPane(ta));
f.pack();
f.setVisible(true);
}
private static int connect(){
try {
Server = new ServerSocket (5000);
ta.append(“Waiting for Client On Port 5000\n\n”);
socketReady = true;
return 1;
} catch (IOException except){
ta.append(except.getMessage() +"\n");
return 0;
}
}
private static int disconnect(){
try {
connected.close();
ta.append("Closing current client connection.\n\n");
ta.append("Waiting for another client to establish a new session\n");
return 0;
} catch (IOException except){
ta.append(except.getMessage() +"\n");
return 1;
}
}
private static void initEventButtons(){
// Lazy way to rapidly create an event ... :P
connectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
connect();
} catch (Exception exc) {
}
}
});
disconnectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
disconnect();
} catch (Exception exc) {
ta.append("DISCONNECTED\n");
}
}
});
}
public static void main(String argv[]) throws Exception {
String fromclient = "";
guiInit();
initEventButtons();
socketReady = false;
ta.append( "Click Connect Button to Start Initializing the Server Session...\n");
while(true)
{
if(socketReady) {
// waiting for client
connected = Server.accept();
// got one client connected with server
ta.append( "SESSION ESTABLISHED " +
connected.getInetAddress() + ":" +connected.getPort()+"\n");
inFromClient = new ObjectInputStream(connected.getInputStream());
outToClient = new ObjectOutputStream(connected.getOutputStream());
outToClient.flush();
ta.append("Send 'Q' or 'q' to Quit \n\n");
while ( true )
{
try {
// try to do read from socket, if disconect we going to get error so just break the load to start new one
fromclient = (String) inFromClient.readObject();
} catch (Exception exc) {
ta.append("Lost connection with client...\n\n");
break;
}
if ( fromclient.equals("q") || fromclient.equals("Q") )
{
ta.append("Lost connection with client...\n\n");
ta.append("\nclient " + connected.getPort() + "chat session ended.\nWaiting for new connection...\n\n");
connected.close();
break;
}
else
{
ta.append( "client> " + fromclient + "\n");
}
}
} // enf if socketReady
else { // else if socket ready
// let the current thread sleep for a second, Didn't want the apps to 'rampage' with maximum speed looping...
Thread.sleep(1);
}
}
}
}