java - Label refresh function does not work -
i'm trying setup function takes input user , prints onto label , updates per entry. updating occur through removing old label , adding label updated value. text center-aligned. while i'm able label print current value of "entry", without removing label old value. wondering how able correct issue?
import acm.graphics.*; import acm.program.*; public class testcanvas extends consoleprogram { public void run() { gcanvas canvas = new gcanvas(); add(canvas); string entry =""; while(true) { entry += readline("give me word: "); if(entry=="") break; glabel label = new glabel(entry); label.setlocation(200-label.getwidth()/2, 60+label.getheight()); label.setfont("times new roman-24"); // remove old label , update // label current value "entry" canvas.remove(label); canvas.add(label); } } }
your infinite loop prevents label updating. need ui thread, update asynchronously.
Comments
Post a Comment