为什么textarea不会正确更新java [英] why won't textarea update properly java
本文介绍了为什么textarea不会正确更新java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从客户端到服务器端获取FIX消息,在那里我为服务器创建了一个UI。唯一的问题是,当我尝试将消息输出到textarea时,它将不会更新,而其他程序工作,例如文本字段将在调用时全部正确更新。我将动作事件放在按钮上。
我把消息的输出放在while循环中,这会影响它输出的方式吗?
问题区域
字符串 inputLine ,outputLine;
尝试 {
while ((inputLine = in.readLine())! = null)
{
System.out.println( 服务器: + inputLine);
tfFIXMsg.append(inputLine + \ n\\\
\ n);
行动事件
/ * * ActionEvent handler - 当用户单击按钮时调用。 * /
@覆盖
public void actionPerformed(ActionEvent evt){
// 获取输入的字符串进入TextField tfPort,转换为int
port = Integer.parseInt(tfPort.getText());
fileLocation = tfLocation.getText();
String csvName = fileLocation;
ServerSocket serverSocket = null;
尝试 {
serverSocket = new ServerSocket(port);
}
catch (IOException e)
{
System.err.println( 无法侦听端口:57635。);
System.exit( 1 );
}
Socket clientSocket = null;
System.out.println( 等待连接.....);
try {
clientSocket = serverSocket.accept();
}
catch (IOException e)
{
System.err.println( 接受失败。);
System.exit( 1 );
}
System.out.println( 连接成功);
System.out.println( 等待输入.....);
PrintWriter out = null;
尝试 {
out = new PrintWriter(clientSocket.getOutputStream(),
true);
} catch (IOException e){
// TODO自动生成的捕获块
e.printStackTrace();
}
BufferedReader in = null;
尝试 {
in = new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()));
} catch (IOException e){
// TODO自动生成的捕获块
e.printStackTrace();
}
String inputLine,outputLine;
尝试 {
while ((inputLine = in.readLine ())!= null)
{
System.out.println( 服务器: + inputLine);
tfFIXMsg.append(inputLine + \ nn \
\\\
跨度>);
if (inputLine.trim()。equals( 再见。)){
System.out.println( 退出程序);
break ;
}
扫描仪输入1 = 新扫描仪(新文件( csvName));
扫描仪输入2 = 新扫描仪(新文件(csvName));
扫描仪输入3 = 新扫描仪(新文件(csvName));
扫描仪输入4 = 新扫描仪(新文件(csvName));
字符串 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.setText(outputLine);
input1.close();
input2.close();
input3.close();
input4.close();
}
} catch (FileNotFoundException e){
// TODO自动生成的捕获块
e.printStackTrace();
} catch (IOException e){
// TODO自动生成的捕获块
e.printStackTrace();
}
out.close();
尝试 {
in.close();
} catch (IOException e){
// TODO自动生成的捕获块
e.printStackTrace();
}
尝试 {
clientSocket.close();
} catch (IOException e){
// TODO自动生成的捕获块
e.printStackTrace();
}
尝试 {
serverSocket.close();
} catch (IOException e){
// TODO自动生成的捕获块
e.printStackTrace();
}
}
更具体地说
tfFIXMsg.append (inputLine + \ n \ nn \ n);
解决方案
这是一个已知问题。看到这个
http://www.javamex。 com / tutorials / threads / invokelater.shtml [ ^ ]
I'm trying to get a FIX message from the client side to server side, where I created a UI for the server. The only problem is that, when I try to output the message onto the textarea, it won't update, while the rest of the program work, such as the text fields will all properly update, when called. I have the action event put onto a button click.
I put the output of the message inside a while loop, does that affect the way it outputs?
problem area
String inputLine, outputLine;
try {
while ((inputLine = in.readLine()) != null)
{
System.out.println ("Server: " + inputLine);
tfFIXMsg.append( inputLine+ "\n\n\n");
action event
/** ActionEvent handler - Called back when user clicks the button. */
@Override
public void actionPerformed(ActionEvent evt) {
// Get the String entered into the TextField tfPort, convert to int
port = Integer.parseInt(tfPort.getText());
fileLocation = tfLocation.getText();
String csvName = fileLocation;
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(port);
}
catch (IOException e)
{
System.err.println("Could not listen on port: 57635.");
System.exit(1);
}
Socket clientSocket = null;
System.out.println ("Waiting for connection.....");
try {
clientSocket = serverSocket.accept();
}
catch (IOException e)
{
System.err.println("Accept failed.");
System.exit(1);
}
System.out.println ("Connection successful");
System.out.println ("Waiting for input.....");
PrintWriter out = null;
try {
out = new PrintWriter(clientSocket.getOutputStream(),
true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader in = null;
try {
in = new BufferedReader(
new InputStreamReader( clientSocket.getInputStream()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String inputLine, outputLine;
try {
while ((inputLine = in.readLine()) != null)
{
System.out.println ("Server: " + inputLine);
tfFIXMsg.append( inputLine+ "\n\n\n");
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.setText(outputLine);
input1.close();
input2.close();
input3.close();
input4.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.close();
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
clientSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
serverSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
More Specifically
tfFIXMsg.append( inputLine+ "\n\n\n");
解决方案
This is a known issue. See this
http://www.javamex.com/tutorials/threads/invokelater.shtml[^]
这篇关于为什么textarea不会正确更新java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文