このコードは構文エラー( "{"を除く)を示していますが、他の何かが間違っていると思います。
public class CircleController extends JPanel {
private JComboBox product1=new JComboBox(Application.listArray);
private JLabel jlb1=new JLabel();
//..........some fields more
// constructor....
public CircleController() {
// Panel to group labels
JPanel panel1 = new JPanel();
//..........some labels....
//another panel
JPanel panel2 = new JPanel();
panel2.setLayout(new GridLayout(4,4,20,20 ));
panel2.add(product1);
panel2.add(jlb1);
およびエラーのあるコードの一部
//product1 is combobox, jlbt is label wich I want to set when I selected item from combobox
product1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) { // in this line shows me an error
(Product name:Application.manu) {
if ((String)product1.getSelectedItem()==name.getName()){
String price1=Double.toString(name.getPrice());
jlb1.setText(price1);
}
}
if (model != null){
model.setProduct((String)product1.getSelectedItem());}}
});
プログラムはこのコードで正常に動作しました
product1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (model != null){
model.setProduct((String)product1.getSelectedItem());}}
});
しかし、私がこのステートメントを追加すると(このステートメントはチェックされ、それは良いです)
(Product name:Application.manu) {
if ((String)product1.getSelectedItem()==name.getName()){
String price1=Double.toString(name.getPrice());
jlb1.setText(price1);
}
}
product1.addItemListener(new ItemListener() {....
プログラム内にエラーが表示されます
ItemListener
ラベルを設定するために別のものを追加する必要がありますか?