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
Post a Comment