Java-Assign string within array to JButton randomly within a for loop. Each element once -


public static void main(string[] args){      string[] word = {" ", " itsy " , " bitsy ", " spider ", " went " , " " ,                        " ", " water ", " spout. ", " down ", " came ", " " ,                        " rain ", " , ", " flushed ", " ", " spider ", " out. "};      random random = new random();       jframe frame = new jframe();      frame.setlayout(new borderlayout());      frame.settitle("javagame");      frame.setsize(600,600);      frame.setdefaultcloseoperation(jframe.exit_on_close);       jpanel northpanel= new jpanel(new gridlayout(3,6));      (int i=0; i<18; i++) {          jbutton button = new jbutton();          northpanel.add(button);          button.settext(word[random.nextint(word.length)]);      } } 

i'm looking plug in make sure each element populates once.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -