Results 1 to 3 of 3
  1. #1
    jls7168 is offline Member
    Join Date
    Nov 2008
    Rep Power

    Default setText() problem

    I need to get the results from a for loop and display them in a TextArea in they order they complete. However, the way I have it set up it will only display the last thread finished in the for loop. Here is the code and any help would be appreciated.
    Java Code:
    	class Horse extends Thread {
    			int racelen = 0;
    			JTextArea resultsTextArea = null;
    			int move;
    			int move1;
    			int total;
    			long totalTime;
    	public Horse(String str, int len, JTextArea results){
    			racelen = len;
    			resultsTextArea = results;	
    			public void run(){
    				long time = System.currentTimeMillis();
    				for (int total = 0; total < 100; total++){
    					move = (int)(Math.random()*100);
    					move1 = (int)(Math.sqrt(move));
    					total += move1;
    					try {
    						sleep((int)(Math.random() * 1000));
    					}catch (InterruptedException e) {}
    				totalTime =(System.currentTimeMillis() - time);
    				resultsTextArea.setText("Name\t\t" + "Priority\t\t" + "Time\n" +
    						 getName() + "\t\t" + getPriority() +"\t\t"+ totalTime + "\n" );	

  2. #2
    jls7168 is offline Member
    Join Date
    Nov 2008
    Rep Power


    Nevermind I figured it out. Thanks.

  3. #3
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Rep Power


    Please go to the top of this page and click Thread Tools -> Mark This Thread As Solved.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

Similar Threads

  1. [SOLVED] new2java- gettext settext
    By obdi in forum New To Java
    Replies: 4
    Last Post: 07-21-2008, 09:28 AM
  2. setText in event
    By sniezna.stopa in forum SWT / JFace
    Replies: 0
    Last Post: 06-20-2008, 02:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts