java - Pass array into ActionListener, another array triggers events -


below code i've got. i'm trying create array of 6 random numbers , 30 check boxes. in action listener, want validate 6 boxes user clicked happen 6 random numbers. however, can't pull down random number array actionlistener. can give me guidance please? i'm total newb @ this. int[] rand array giving me grief.

import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.util.*;  public class jlottery2 extends jframe implements actionlistener {    int actioncounter = 0;    int matchtally = 0;     final int maxboxes = 6;     final int width = 500;     final int height = 200;    jcheckbox[] boxes = new jcheckbox [30];     public jlottery2()    {       super ("~*~*~ jlottery 2 ~*~*~");       setdefaultcloseoperation(jframe.exit_on_close);       setlayout (new flowlayout());       setsize(width, height);        system.out.println("constructor");        //great check boxes , assign them value             (int count=0 ; count < 30; count++)       {          boxes[count] = new jcheckbox (integer.tostring(count));          add(boxes[count]);          boxes[count].addactionlistener(this);       }        int[] rand = new int[maxboxes];        (int = 0; < maxboxes; i++)       {          rand[i] = (int)(math.random() * 30);          //incase tries generate same random number           (int j = 0; j < i; j++)          {             if(rand[i] == rand[j])             {               i--;              }          }       }         setvisible(true);    }     public void actionperformed(actionevent e, )    {             system.out.println(rand[5]);        if(actioncounter < maxboxes)       {          system.out.println("action triggered");          object source = e.getactioncommand();          system.out.println(source);                   actioncounter++;          system.out.println(actioncounter);          }       else        {          system.out.println("you reached max @ " + actioncounter);       }     }      public static void main(string[] args)    {       jlottery2 prog = new jlottery2();    } } 

make rand class instance field boxes

public class jlottery2 extends jframe implements actionlistener {      //...      jcheckbox[] boxes = new jcheckbox [30];      int[] rand;       public jlottery2()      {          //...          rand = new int[maxboxes];  

this gives class level context field, allows access anywhere within class


Comments