私は配列のすべての2番目の要素を取得したいと思います(この場合は2と4です)。JComboBox ActionListenerが機能しません
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class tester2 extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
JFrame f = new JFrame();
String [] corps = {"IBM", "Apple", "Oracle", "Google"};
JComboBox <String> cb = new JComboBox <>();
JLabel l1 = new JLabel();
public tester2() {
f.setSize(500, 300);
f.setLayout(new BorderLayout());
f.setVisible(true);
f.setTitle("Tester 2");
f.setLocationRelativeTo(null);
f.add(cb, BorderLayout.NORTH);
f.add(l1);
// Combo
cb.removeAllItems();
cb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int i = 1; i < corps.length; i=+2) {
String tempRes = corps[i];
System.out.println(tempRes);
cb.addItem(tempRes);
}
}
});
}
public static void main(String[] args) {
new tester2();
}
}
詳細、詳細、詳細、詳細、詳細、詳細、詳細、詳細、詳細、詳細、詳細、詳細、詳細、詳細、より詳細、詳細。
おかげ
「私は戻って、アレイの毎秒の要素を取得したいのですが(そう、このケース2及び図4に。)。」*私は飛んでみたいですアイスクリームを排泄するポニー。今私たちは両方とも我々が望むものについて話し合った。 **あなたは**質問**を持っていますか? – XtremeBaumer
*で0ないであなたのループを開始 –
なぜこのコードは結果を戻しませんか?たとえば、System.out.println(tempRes); - >何も印刷しません。 – fucorogu