multithreading - Printing a list array which uses threads to a text area in java -
i having problems storing , printing list array uses threads. want store list of threads in list array , print them text area can sorted user. code below array class , transaction class.
import java.util.arraylist; /** * @author b00533474 */ public class array { arraylist<transaction> transactionlist = new arraylist<transaction>(); // variables private final transaction nexttransaction; public static int inint2 = tranacc.inint2; public static int inint3 = tranacc.inint3; public static string inint1 = tranacc.inint1; //public static void main(string[] args){ public array(){ nexttransaction = new transaction(inint1, inint2, inint3, 2000); transactionlist.add(nexttransaction); transactionlist.get(3); } /*public static void main(string[] args){ array ar = new array(); ar.add(nexttransaction); } * */ }
the variables inint1 etc class called tranacc main gui of project.
package bankassig; /** * * @author b00533474 */ public class transaction { string type; int amount; int wknum; int balance; public transaction(string ty, int am, int wk, int bal) { type = ty; amount = am; wknum = wk; balance = bal; } }
my problem implementing/using list area, going add action listener button on gui call list area , print transactions in text unsure of code write ( know action listener not calling list array).
any appreciated , if need provide anymore code happy so.
how implement list array , use print out values of variables used?
overwrite inherited (from java.lang.object) tostring() method in transaction class. in tostring() method, can put string variable data in format makes sense user, , return it. can iterate through transactions in array class's list, call tostring() method, , put in gui. like:
for (transaction trans : yourarrayobj) { yourtextarea.append(trans.tostring()); }
Comments
Post a Comment