2013-03-05 3 views
1

누군가가 도와 주시겠습니까? 줄에 형식 오류가 잘못 시작되었습니다.}); 나는 이것을 고치는 방법에 대해 매우 혼란 스럽다. 어떤 도움이라도 대단히 감사하겠습니다. 코드는 다음과 같습니다 :형식 오류 시작이 잘못되었습니다.

public SubokUlit(){ 
    String mgaPagkainTo[] = {"PM1 (Paa/ Spicy Paa with Thigh part)","PM2 (Pecho)","PM3 (Pork Barbeque 4 pcs.)","PM4 (Bangus Sisig)","PM5 (Pork Sisig)","PM6 (Bangus Inihaw)","SM1 (Paa)","SM2 (Pork Barbeque 2 pcs.)","Pancit Bihon","Dinuguan at Puto","Puto","Ensaladang Talong","Softdrinks","Iced Tea","Halo-Halo","Leche Flan","Turon Split"}; 
    JFrame frame = new JFrame("Mang Inasal Ordering System"); 
    JPanel panel = new JPanel(); 
    combo = new JComboBox(mgaPagkainTo); 
    combo.setBackground(Color.gray); 
    combo.setForeground(Color.red); 
    panel.add(combo); 
    frame.add(panel); 

    combo.addActionListener(new ActionListener(){ 
     public void actionPerformed(ActionEvent e){ 
      String str = (String)combo.getSelectedItem(); 
      a = str; 
      if(a == "PM1 (Paa/ Spicy Paa with Thigh part)"){ 
       Wew(); 
      } 
      else if(a == "PM2 (Pecho)"){ 
       Wew1(); 
      } 
     }); // I am getting an error in this line 
    } 

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame.setSize(300,100); 
    frame.setVisible(true); 
} 

답변

4

귀하의 ); 잘못되어

combo.addActionListener(new ActionListener(){ 
    public void actionPerformed(ActionEvent e){ 
     String str = (String)combo.getSelectedItem(); 
     a = str; 
     // Comparing strings should use equals, not == 
     if(a.equals("PM1 (Paa/ Spicy Paa with Thigh part)")){ 
      Wew(); 
     } else if(a.equals("PM2 (Pecho)")){ 
      Wew1(); 
     } 
    } // <<== Not here: this brace ends the method 
}); // <<== It should be after the brace that ends the anonymous class 
+1

일을 - 나는 우리가 "왜 내 WEW/Wew1 메소드가 호출되지 않습니다"입니다 볼 수 있습니다 다음 질문을 가정) –

+0

@Andreas 당신을 예 맞아 그건 내 다음 질문이야. 다음 질문에 대한 새로운 토론을 시작해야합니까? –

+1

그게 필요하지 않습니다 - 참조 http://stackoverflow.com/questions/767372/java-string-equals-versus –

1

}); // I am getting an error in this line 
} 

에서 코드를 변경

: 그것은 다음 줄에 } 후해야

} // I am getting an error in this line 
}); 
^ 
0

이 대신이

} // I am getting an error in this line 
}); 

을 수행

}); // I am getting an error in this line 
} 
관련 문제