Hi, these are my classes.when i run my MainClient class,one frame will be shown that get text from client and then send it to the server.at the first time when i click on the Send button,it will work correctly and send data to the server but suddenly the frame will confused and I can not do any thing like writing or clicking on the button!!please help me.
MainClient class:
//these are in the main(String[] args)
MainFrame farme = new MainFrame();
farme.setVisible(true);
c = new Socket("localhost", 5050);
os = new PrintWriter(c.getOutputStream(), true);
is = new BufferedReader(new InputStreamReader(c.getInputStream()));
//this method is not in the main(String[] args)
public static void active() {
String teXt = MainClient.getText();
System.out.println(teXt);
os.println(teXt);
String line = is.readLine();
System.out.println("Text received: " + line);
}
my gui class which get text from client and by clicking on the send button will send that text to the server:(Send button action performed)
public ChatFrame(InformationClass client) {
initComponents();
jButton1.setEnabled(false);
this.client = client;
jTextArea2.setText("");
}
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");
MainClient.active();
}
private void clear() {
jTextArea1.setText("");
}