使用单独的 ImageIcon 创建多个 JToggleButton
Creating multiple JToggleButton with indivdual ImageIcon
ImageIcon img_1 = new ImageIcon("src/menu/btn_1.jpg");
ImageIcon img_2 = new ImageIcon("src/menu/btn_2.jpg");
ImageIcon img_3 = new ImageIcon("src/menu/btn_3.jpg");
ImageIcon img_4 = new ImageIcon("src/menu/btn_4.jpg");
ImageIcon img_5 = new ImageIcon("src/menu/btn_5.jpg");
ImageIcon img_6 = new ImageIcon("src/menu/btn_6.jpg");
ImageIcon img_7 = new ImageIcon("src/menu/btn_7.jpg");
ImageIcon img_8 = new ImageIcon("src/menu/btn_8.jpg");
ImageIcon img_9 = new ImageIcon("src/menu/btn_9.jpg");
bgNumbers = new ButtonGroup();
btnNumbers = new JToggleButton[9];
for (int i = 0; i < 9; i++) {
btnNumbers[i] = new JToggleButton(???);
.....
.....
}
如何将个人 ImageIcon img_1、img_2 ...... img_9 插入循环?
将它们添加到数组而不是单个变量。 – Gábor Bakos 4 月 4 日 7:35
ImageIcon img_1 = new ImageIcon("src/menu/btn_1.jpg");
ImageIcon img_2 = new ImageIcon("src/menu/btn_2.jpg");
ImageIcon img_3 = new ImageIcon("src/menu/btn_3.jpg");
ImageIcon img_4 = new ImageIcon("src/menu/btn_4.jpg");
ImageIcon img_5 = new ImageIcon("src/menu/btn_5.jpg");
ImageIcon img_6 = new ImageIcon("src/menu/btn_6.jpg");
ImageIcon img_7 = new ImageIcon("src/menu/btn_7.jpg");
ImageIcon img_8 = new ImageIcon("src/menu/btn_8.jpg");
ImageIcon img_9 = new ImageIcon("src/menu/btn_9.jpg");
bgNumbers = new ButtonGroup();
btnNumbers = new JToggleButton[9];
for (int i = 0; i < 9; i++) {
btnNumbers[i] = new JToggleButton(???);
.....
.....
}
如何将个人 ImageIcon img_1、img_2 ...... img_9 插入循环?
将它们添加到数组而不是单个变量。 – Gábor Bakos 4 月 4 日 7:35