寻求一些帮助。我有一个组合框中的平面(字符串)列表,供用户选择,当选择特定平面时,我希望能够引用它。我大多是自学成才所以请耐心等待
$group
String[] planeTitles = new String[] {"Focke-Wulf Fw 190", "Messerschmitt Bf 109","Messerschmitt Me 262", "Supermarine MKs 24 Spitfire",
"Yakovlev Yak-3", "Vought F4U Corsair", "Lockheed P-38 Lightning", "North American P-51 Mustang", "Mitsubishi A6M Zero"};
JComboBox<String> planeList = new JComboBox<>(planeTitles);
//添加到父容器(例如JFrame):
add(planeList);
//获取所选项目:
planeList.addActionListener (
new ActionListener () {
public void actionPerformed(ActionEvent e) {
String selectedPlane = (String) planeList.getSelectedItem();
System.out.println("You seleted the: " + selectedPlane);
textPane.setText("You seleted the: " + selectedPlane);
}
});
飞机后来需要与用户生成的数据进行比较。基本上我的问题是你如何为每个平面创建一个对象并将其分配给我当前的平面列表?我知道这可能有点太多了......