1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| public void initTab() {
JPanel temp = new JPanel();
this.add(temp);
this.tab = new Couleur[10][15];
this.tabi = new int[10][15];
Random random = new Random();
int alea;
temp.setLayout(new GridLayout(10,15,0,0));
for(int i = 0;i<10;i++) {
for(int j=0; j<15; j++) {
alea = random.nextInt(3);
if(alea == 0) {
this.tab[i][j] = new Muffin();
temp.add(tab[i][j]);
this.tabi[i][j] = 1;
}
if(alea == 1) {
this.tab[i][j] = new Cookie();
temp.add(tab[i][j]);
this.tabi[i][j] = 2;
}
if(alea == 2) {
this.tab[i][j] = new Bonbon();
temp.add(tab[i][j]);
this.tabi[i][j] = 3;
}
}
}
this.setSize(800, 800);
this.setLocationRelativeTo(null);
this.setIconImage(new ImageIcon(getClass().getResource("/img/cookie.png")).getImage());
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
} |