i'm using netbeans/gui make fantasy basketball game program. i'm trying create methods create arraylists, way can call method array every time need 1 of button events, rather recode array under each individual event. array list method loads data team name listbox created in design window. code follows:
public class jfmarchmadness extends javax.swing.jframe { public jfmarchmadness() { initcomponents(); } //creates arraylist , loads data arraylist of type string (lstconfteams) void createctarraylist () { arraylist<basketballteam> alcteams=new arraylist <>(); string ctteamname; string ctstatus=""; int ctwins=0; int ctlosses=0; double ctwinlosspct=0; (int icount = 0; icount <lstconfteams.getmodel().getsize(); icount++) { ctteamname=lstconfteams.getmodel().getelementat(icount); alcteams.add(new basketballteam(ctstatus,ctteamname,ctwins,ctlosses,ctwinlosspct)); } } private void btnplaymouseclicked(java.awt.event.mouseevent evt) { // call createctarraylist method , begin loop createctarraylist (); int ictcount; (ictcount=0; ictcount<alcteams.size; ictcount++){ // } }
right gets error can't find arraylist: alcteams when try call in loop statement. did write method incorrectly or calling incorrectly?
the declaration alcteams
should located under class
not method
.
like this:
public class jfmarchmadness extends javax.swing.jframe { arraylist<basketballteam> alcteams=new arraylist <>(); public jfmarchmadness() { initcomponents(); } //creates arraylist , loads data arraylist of type string (lstconfteams) void createctarraylist () { string ctteamname; string ctstatus=""; int ctwins=0; int ctlosses=0; double ctwinlosspct=0; (int icount = 0; icount <lstconfteams.getmodel().getsize(); icount++) { ctteamname=lstconfteams.getmodel().getelementat(icount); alcteams.add(new basketballteam(ctstatus,ctteamname,ctwins,ctlosses,ctwinlosspct)); } } private void btnplaymouseclicked(java.awt.event.mouseevent evt) { // call createctarraylist method , begin loop createctarraylist (); int ictcount; (ictcount=0; ictcount<alcteams.size; ictcount++){ // } }