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

    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){
    			super(str);
    			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
    Posts
    9
    Rep Power
    0

    Default

    Nevermind I figured it out. Thanks.

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

    Default

    Please go to the top of this page and click Thread Tools -> Mark This Thread As Solved.
    -MK12
    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
  •