所以我有一个按钮,假设向我的摇摆 gui 添加一个(子)比赛选项以创建混合字符实际更新类和统计值的代码在控制台中工作,但 GUI 方面现在证明很困难我的代码动态执行创建新代码,但在添加按钮内部分层,它需要修改父面板而不是自身。想法?
if (e.getActionCommand().equals("AddRaceBox")){
JButton cb = (JButton)e.getSource();
String[] cRace = new String[75];
JComboBox[] raceBox = new JComboBox[2];
raceBox[1] = new JComboBox();
for (int i=0; i<75; i++){
cRace[i] = nala.getRaceName(i);
raceBox[1].addItem(cRace[i]);
}
cb.add(raceBox[1]);
ImageIcon deleteRaceIcon = createImageIcon("1359702329_delete_user.png", "add race icon");
JButton addRaceButton1 = new JButton(deleteRaceIcon);
addRaceButton1.addActionListener(this);
addRaceButton1.setActionCommand("AddRaceBox");
addRaceButton1.setSize(new Dimension(32, 32));
cb.add(addRaceButton1);
cb.revalidate();
cb.repaint();
System.out.println("Add Race Clicked");
}