Hi,
i have asked this question 2 days before but I can not edit that(I don't know why)also i have changed some part of my classes.also I have checked it a lot but really I don't know that why it returns null value(on the console is written :Client says: null
),please help me.
at first i get the text from a text area which get text from client and then i will set it to my text area which is the output(like chat frame in Yahoo Messenger) and then i will send that text to my MainClient class.
my send button action performed in my chat frame:(I have tested the String text in the chat frame and it wasn't null)
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
submit();
clear();
}
private void submit() {
String text = jTextArea1.getText();
jTextArea2.append(client.getCurrentName() + " : " + text + "\n");
MainClient.setText(client.getCurrentName() + " : " + text + "\n");
}
my MainClient class:(a part of that)
private static String text;
public static String getText() {
return text;
}
public static void setText(String text) {
MainClient.text = text;
}
static boolean closed = false;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String teXt = getText();
try {
os = new PrintWriter(c.getOutputStream(), true);
is = new BufferedReader(new InputStreamReader(c.getInputStream()));
} catch (IOException ex) {
Logger.getLogger(MainClient.class.getName()).log(Level.SEVERE, null, ex);
}
if (c != null && is != null && os != null) {
try {
os.println(teXt);//send data over socket.
String line = is.readLine();//recieve text from server.
System.out.println("Text received: " + line);
c.close();
} catch (IOException ex) {
System.err.println("read Failed");
}
}
}}
my MainServer class:(a part of that)
try {
BufferedReader streamIn = new BufferedReader(new InputStreamReader(client.getInputStream()));
boolean done = false;
String line =null;
while (!done ) {
line = streamIn.readLine();
if (line.equalsIgnoreCase("bye")) {
done = true;
} else {
System.out.println("Client says: " + line);
}
}
streamIn.close();
client.close();
server.close();
} catch (IOException e) {
System.out.println("IO Error in streams " + e);
}
}}
At first I will run the MainServer and then I will run the MainClient(which will show the chat frame).
EDIT:please start reading from this part: these are two classes ,one for gui and the other for client.(network) it returns nothing on the console for server so it will return nothing to the client.please help me thanks. my GUI class:(a part of that) (like a chat frame which by clicking on the Send button .I will send something for the server)
my gui class(chat frame) a part of that:
private void SendActionPerformed(java.awt.event.ActionEvent evt) {
setButtonIsSelected(true);
submit();
clear();
}
private void submit() {
String text = jTextArea1.getText();
jTextArea2.append(client.getCurrentName() + " : " + text + "\n");
MainClient.setText(client.getCurrentName() + " : " + text + "\n");
}
private static boolean buttonIsSelected = false ;
public static boolean isButtonIsSelected() {
return buttonIsSelected;
}
public static void setButtonIsSelected(boolean buttonIsSelected) {
ChatFrame.buttonIsSelected = buttonIsSelected;
}
my MainClient class:(a part of that)
show a chat frame.
if ( ChatFrame.isButtonIsSelected() == true) {
String teXt = getText();
System.out.println(teXt);
os.println(teXt);
String line;
line = is.readLine();
System.out.println("Text received: " + line);
}
at first I will run the client class So the gui class will be run which name is chat Frame.