public static void main(String[] args){
String[] word = {" The ", " itsy " , " bitsy ", " spider ", " went " , " up " ,
" the ", " water ", " spout. ", " Down ", " came ", " the " ,
" rain ", " and ", " flushed ", " the ", " 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));
for (int i=0; i<18; i++) {
JButton button = new JButton();
northPanel.add(button);
button.setText(word[random.nextInt(word.length)]);
}
}
我正在寻找插件以确保每个元素只填充一次。