for 循环不起作用。我得到“选择无法解析为变量”。我想将一组选项添加到添加到泛型列表中的多个 Choice 对象中。在此示例中,您可以看到其中一个对象 (DidWell1) 。
import java.awt.Choice;
import java.awt.EventQueue;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
public class testing {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
testing window = new testing();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public testing() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final Choice DidWell1 = new Choice();
DidWell1.setBounds(119, 36, 135, 20);
frame.getContentPane().add(DidWell1);
List<Choice> list = new ArrayList<Choice>();
list.add(DidWell1);
String option = "Friday";
For(Choice choice: list){
choice.add( option );
}
}
}