Printing arraylist contents in Jtextarea
Hi everyone, I am trying to build a program that will estimate download time for a given file size and internet speed. user will use a simple GUI interface with two text field (to input filesize and net speed) and a button labeled calculate that will show the estimated download time in a textarea just below the calculate button.
I have three classes calculation class for calculation, gui class for user interface and of course the main class.
after calculation I have stored the result (i.e. day hour minutes and seconds) in a ArrayList with string type.
problem is Jtextarea won't allow me to print an arraylist with its setText() method. I am new to java programming and I have been stuck for the last two days with this problem. my program would be complete if it were not for this type conversion problem.
please help
Re: Printing arraylist contents in Jtextarea
Create a String, concatenate each ArrayList item to the String, and then send the setText() method the String you created. If you need any help with that, just ask.
Re: Printing arraylist contents in Jtextarea
Quote:
Originally Posted by
aussiemcgr
Create a String, concatenate each ArrayList item to the String, and then send the setText() method the String you created. If you need any help with that, just ask.
Thanks for your reply. I have tried what you said here. but there is a problem with this solution. it works fine first time I click the calculate button. but when I click the button second time the output from the first calculation is also added to the second calculation.
for example the first output was "5 minutes 24 seconds" and the second is "3 minutes 5 seconds". the second output also adds the first output like "5 minutes 24 seconds 3 minutes 5 seconds" as long as the program runs and calculate button is clicked.
I suppose this happens because strings are immutable. if it were integer I could have written a method to clear the variable. but with string that's simply not possible.
Re: Printing arraylist contents in Jtextarea
You can clear Strings, just set it to: ""
Or create a new String each time.
Re: Printing arraylist contents in Jtextarea
I think I have found the solution. instead of using a class variable of string type I chose to use a local string variable in a method. in this was the variable gets destroyed each time execution of that method ends.