Reputation: 345
This code shows me syntax error (excepted "{") but I think something else is wrong.
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);
and part of code with error
//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());}}
});
program worked fine with this code
product1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (model != null){
model.setProduct((String)product1.getSelectedItem());}}
});
but when I add this statement (this statement is checked and it is good)
(Product name:Application.manu) {
if ((String)product1.getSelectedItem()==name.getName()){
String price1=Double.toString(name.getPrice());
jlb1.setText(price1);
}
}
inside product1.addItemListener(new ItemListener() {....
program shows error
Do I have to add another ItemListener
to set label?
Upvotes: 2
Views: 462
Reputation: 32391
The compile error is actually related to this line:
(Product name:Application.manu) {
It looks like a foreach, so it should be:
for (Product name:Application.manu) {
Upvotes: 2