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 ạ :frowning:

Hi Phan Anh.

  1. Trước khi code UI bạn nên học Java core trước.
  2. Xem lại if.
1 Like

Đọc đến đây biết kiến thức cơ bản còn chưa nắm rõ rồi

1 Like

Học lại về Core đi bạn ơi, hàm if sai tùm lum kìa

1 Like

trước khi học java bạn đã học ngôn ngữ gì rồi sao viết if lạ thế …

1 Like

Xem lại Java core nha bạn. Bài viết đơn giản, dễ hiểu nhất:

1 Like

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){...}

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?