抱歉,我是 java 的菜鸟,但是如何初始化变量 petList 而不将其设置为 null?
for (int x = 0;x<= buttonPressed;x++){
println("adding box");
String[] petStrings = { "Withdraw", "Deposit", "Blah", };
//Create the combo box, select item at index 4.
@SuppressWarnings({ "rawtypes", "unchecked" })
JComboBox petList[] = null;// = new JComboBox(petStrings);
petList[x] = new JComboBox(petStrings);
petList[x].setSelectedIndex(1);
petList[x].setBounds(119, (buttonPressed *20)+15, 261, 23);
contentPane.add(petList[x]);
}