?
Solved

a question to girionis

Posted on 2003-03-12
2
Medium Priority
?
145 Views
Last Modified: 2011-08-18

hi i have a client server application.
in the server side i have two buttons(3 textfileds), and on the client side have just 4 textfileds
to recive data from server.

the problem is that i can't get the data on the other side by pressing the check button(second one)!!!

here is the code from the server program:

public void actionPerformed(ActionEvent e) {
   if(e.getSource() == send){ // send is a button
       ps.println(tf1.getText());
       ps.println(tf2.getText());
       ps.println(tf3.getText());
       }
       if(e.getSource() ==  check){ //check is a button
       ps.println(tf1.getText()+tf2.getText()+tf3.getText());
   }
 }


the first 3 lines sent (when send button pressed) should be displayed in three textfields(result1,result2,result3) and its working well.
the forth line sent (when the check button pressed) should be displayed in the checkResult in the client GUI which is not working.

here is the client codes witch display those lines:

 try{
 s = new Socket("127.0.0.1", 1024);
 br = new BufferedReader(new InputStreamReader(s.getInputStream()));
       ps = new PrintWriter(s.getOutputStream(), true);      
       line = new String(); // Line to be read from the server
       line2 = new String(); // another Line to be read from the server
       line3 = new String();// another Line to be read from the server


// While there is more data coming... // this is working well when send button pressed!
while ( (line = br.readLine()) != null &&
(line2 = br.readLine()) != null &&
(line3 = br.readLine()) != null)
{
    // putting the incomming line from the
    // server into the result fields.
    result1.setText(line);
    result2.setText(line2);
    result3.setText(line3);
}
  line4 = new String(); // here is the problem why it can't display data into checkResult field when the check button pressed?!!
   while ( (line4 = br.readLine()) != null){
checkResult.setText(line4);
}

}

catch(IOException iExc){}

hope its clear.

0
Comment
Question by:Sharabi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 75 total points
ID: 8126876
 Are you sure that the value you assign at line4 is not null?

  And a performance tip for you. When you initialize Strings always do it with String line = ""; and not String line = new String(); since the latter for each time you do it it creates a new String and consumes memory, while the former as many times as you do it it assigns the same meory location (so you save memory) :-). So the following:

  String line1 = new String();
  String line2 = new String();
  String line3 = new String();

  will consume 3 different memory locations while the following:

  String line1 = "";
  String line2 = "";
  String line3 = "";

  will only consume one memory location and all three instances of String (lien1, line2, line3) will point to the same.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8127132
 So what was the problem?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month9 days, 6 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question