java - Is there a differnt way of writing this code such that it doesn't use a loop -
i trying append string client program. made append statement in while loop. affects program, not sending message realtime onto jtextarea.
how can make program such not use while loop or loop , continue accept messages client , output textarea in real time? perhaps if statement?
while loop area
while ((inputline = in.readline()) != null)
for areas
tffixmsg.append( inputline + "\n\n\n");
and
tfcsvline.append(outputline+"\n\n\n");
it not show message on textarea until while loop done. how can make continue recieve messages client, , able output onto textarea in realtime
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(); }
i suspect code being processed on ui thread. ui thread updates , renders screen. you've while loop running on ui thread, ui cannot update. busy running while loop.
the answer start thread processing. then, use swingworker onto ui thread, , update textbox. necessary because shouldn't update ui objects off ui thread.
here's tutorial started. explain more thoroughly.
Comments
Post a Comment