我正在尝试附加从客户端程序获得的字符串。但是,我这样做是为了让 append 语句处于 while 循环中。然而,这会影响程序,因为不会将消息 REALTIME 发送到 JTextArea。
如何使程序不使用while循环或for循环并继续接受来自客户端的消息并将其实时输出到textarea?也许只是一个 if 语句?
while循环区域
while ((inputLine = in.readLine()) != null)
对于像这样的领域
tfFIXMsg.append( inputLine + "\n\n\n");
和
tfCSVLine.append(outputLine+"\n\n\n");
在 while 循环完成之前,它不会在 textArea 上显示消息。我怎样才能让它继续接收来自客户端的消息,并能够实时将其输出到 textArea
try {
while ((inputLine = in.readLine()) != null)
{
System.out.println ("Server: " + inputLine);
tfFIXMsg.append( inputLine + "\n\n\n");
int pos = inputLine.indexOf(inputLine, 0);
h.addHighlight(50, 60, DefaultHighlighter.DefaultPainter);
if (inputLine.trim().equals("Bye.")) {
System.out.println("Exit program");
break;
}
Scanner input1 = new Scanner(new File(csvName));
Scanner input2 = new Scanner(new File(csvName));
Scanner input3 = new Scanner(new File(csvName));
Scanner input4 = new Scanner(new File(csvName));
String csvline = getCsvLineVal (getLocation34CSV(getTag34Value(Tag34Location(getTagCSV( parseFixMsg(inputLine ,inputLine))), getValueCSV( parseFixMsg(inputLine ,inputLine))), getVal34(input1, input2)), getCSVLine( input3, input4) );
outputLine = compareClientFixCSV( getTagCSV( parseFixMsg(inputLine ,inputLine)), getValueCSV(parseFixMsg(inputLine ,inputLine)), getCSVTag(csvline), getCSVValue(csvline));
out.println(outputLine);
tfCSVLine.append(outputLine+"\n\n\n");
input1.close();
input2.close();
input3.close();
input4.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}