01/10/2018, 15:04
Dùng lệnh "if" trong java
Em mới là sinh viên năm nhất mới tập tọe dùng JAVA GUI. Em đang vướng lỗi này các tiền bối giúp em với ạ.
hardButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
callquestions = callquestions + 1;
if (callquestions == 1);{
questionBox.setText("How many players are there in an ice hockey team?");
answerA.setText("5");
answerB.setText("6");
answerC.setText("7");
answerD.setText("8");}
if (callquestions == 2) ;{
questionBox.setText("What is Zumba?");
answerA.setText("A city in Spain");
answerB.setText("A type of Underwater Sports");
answerC.setText("Name of a famous boxer");
answerD.setText("A Latin inspired dance-based workout");}
if (callquestions == 3) ;{
questionBox.setText("What is number of teams participate in Premier League?");
answerA.setText("18");
answerB.setText("19");
answerC.setText("20");
answerD.setText("21");}
if (callquestions == 4) ;{
questionBox.setText("Where is the 2018 winter olympic games going to be held?");
answerA.setText("Beijing");
answerB.setText("PyeongChang");
answerC.setText("Hanoi");
answerD.setText("Moscow");}
if (callquestions == 5) ;{
questionBox.setText("The FIFA World Cup championship has been awarded every … years?");
answerA.setText("2");
answerB.setText("3");
answerC.setText("4");
answerD.setText("5");
}
Code của em nó như thế này ạ bên ngoài ActionListener em đã
public int callquestions;{
callquestions = 0 } rồi
nhưng mà khi Run thì bấm nút nó chỉ ra đúng câu cuối mà không chạy các câu trước, nhờ các tiền bối giúp em với ạ
Bài liên quan
Hi Phan Anh.
Đọc đến đây biết kiến thức cơ bản còn chưa nắm rõ rồi
Học lại về Core đi bạn ơi, hàm if sai tùm lum kìa
trước khi học java bạn đã học ngôn ngữ gì rồi sao viết if lạ thế …
Xem lại Java core nha bạn. Bài viết đơn giản, dễ hiểu nhất:
GP Coder – 26 Oct 17
Mệnh đề if-else trong java - GP Coder (Lập trình Java)
Hướng dẫn lập trình Java, Design Pattern, Spring, JSF, Primefaces, Collection, Multi-thread, Webservice, SQL, Report, Apache POI.
Bỏ dấu chấm phẩy đi… sao hôm nọ cũng có người đăng code có chấm phẩy lên stackoverflow nhỉ =D
if (callquestions == 1);{...}
thay bằng
if (callquestions == 1){...}