java - Color specific JLabel tiles using random values from another variable -


i develop keno game , confused on how paint specific jlabel tiles (basically specific positions of jlabel array) random variable. thought best idea modify these labels , prob variable arraylists doesn't work. main , thing want achive paint specifics position of array "a" taking prices prob variable iff user press rollbutton. have used several ways , think close want help.

here can find code:

import java.util.random; public class game {      private final int randomnumber = 80;     int prob;     string res;     stringbuilder sb = new stringbuilder();       public void rnumbers() {         (int x = 0; x <= 12; x++) {             random d = new random();             prob = d.nextint(randomnumber) + 0;             sb.append("-");             sb.append(prob);         }     }      public void delete(stringbuilder sb2, string s) {         int start = sb2.indexof(s);         if(start < 0)             return;         sb2.delete(start, start + s.length());     } } 

and gui class

import java.awt.*; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.util.arraylist; import java.util.arrays; import java.util.collections;  import javax.swing.*;  public class guikino extends jframe implements actionlistener {      private jpanel mainpanel;     private jpanel contentpanel;     private jpanel otherpanel;      private color color;      private jtextfield text;     private jtextfield input;      private jbutton rollbutton;     private jbutton clearbutton;      game t = new game();      private jlabel[] = new jlabel[80];      gridlayout gridlayout = new gridlayout();      stringbuilder user = new stringbuilder();      public guikino() {          this.settitle("keno");          // create panels         mainpanel = new jpanel();         contentpanel = new jpanel();         otherpanel = new jpanel();          this.contentpanel = (jpanel) getcontentpane();          contentpanel.add(otherpanel, borderlayout.south);         contentpanel.add(mainpanel, borderlayout.center);          mainpanel.setlayout(new gridlayout(10, 10));         otherpanel.setlayout(new gridlayout(2, 4));          text = new jtextfield("", 20);         input = new jtextfield("", 20);          rollbutton = new jbutton("draw");         rollbutton.addactionlistener(this);          clearbutton = new jbutton("clear");         clearbutton.addactionlistener(this);          otherpanel.add(text);         otherpanel.add(input);         otherpanel.add(rollbutton);         otherpanel.add(clearbutton);          (int j = 0; j < a.length; j++) {             a[j] = new jlabel("");             a[j].setborder(borderfactory.createlineborder(color.black));         }          // cell numbers         (int l = 0; l < a.length; l++) {             a[l].settext("" + l);         }          (int = 0; < a.length; i++) {             mainpanel.add(a[i]);         }      }      arraylist<integer> places = new arraylist<integer>(arrays.aslist(t.prob));     arraylist<jlabel> label = new arraylist<jlabel>(arrays.aslist(a));      public void colored() {         if(!collections.disjoint(label, places)){             //change color!             color=color.red;         }     }      @override     public void actionperformed(actionevent e) {          if (e.getsource() == rollbutton) {             t.rnumbers();             text.settext(t.sb.tostring());             colored();         }          if (e.getsource() == clearbutton) {             text.settext("");             t.delete(t.sb, t.sb.tostring());         }     } } 


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -