JavaFX answer doesn’t show up

I am coding Hangman game with javaFX, somehow the code assumes all of my guesses are wrong and always considered a mistake even if it’s correct. So the user ends up always losing. I think it has something to do with the while loop I am using to make sure all redundancy of any letter is dealt with (like in “banana” if the user enters “a”, the currect progress should be displayed as “-a-a-a” instead of “-a—-“) but i don’t know: here is my controller class as well as word, if you need any other classes let me know!


import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.List;

public class Controller {

    //inject an element defined in fxml to controller!
    @FXML
    //pane is a form container
    private Pane man;
    @FXML
    private Pane base1;
    @FXML
    private Pane base2;
    @FXML
    private Pane base3;
    @FXML
    private Pane pole;
    @FXML
    private Pane rod;
    @FXML
    private Pane rope1;
    @FXML
    private Pane rope2;
    @FXML
    private Text text;
    @FXML
    private Pane buttons;
    @FXML
    private Text winStatus;
    @FXML
    private Text realWord;

    private int mistakes;
    private int correct;
    
    private String[] table;
    private String word;
    private String category;
    private List<String> myLetters;
    private List<String> answer;

    public Controller(){
    }

    public void initialize() {
        base1.setVisible(false);
        base2.setVisible(false);
        base3.setVisible(false);
        pole.setVisible(false);
        rod.setVisible(false);
        rope1.setVisible(false);
        rope2.setVisible(false);
        man.setVisible(false);
        buttons.setDisable(false);
        
        mistakes=0;
        correct=0;
        
        table = Words.getRandomWord(2);
        word=table[1];
        category=table[0];
        
        myLetters = Arrays.asList(word.split(""));
        answer = Arrays.asList(new String[myLetters.size()*2]);
        
        for(int i=0; i<myLetters.size()*2; i++){
            if(i%2==0){
                answer.set(i, "_");
            }else{
                answer.set(i, " ");
            }
        }
        String res = String.join("", answer);
        text.setText(res);
        
        //hide winstatus and realword in case of a new game! 
        winStatus.setText("");
        realWord.setText("");
    }

    //when do i call for u ?when the event i declared happened!
    public void onClick(ActionEvent event){
        //getText return string not char
        String letter = ((Button)event.getSource()).getText();
        ((Button) event.getSource()).setDisable(true);
        
        if(myLetters.contains(letter)){
            correct++;
            int letterIndex = myLetters.indexOf(letter);
            while (letterIndex != -1) {
                myLetters.set(letterIndex, "*");
                answer.set(letterIndex*2, letter);
                letterIndex = myLetters.indexOf(letter);
                String res = String.join("", answer);
                text.setText(res);
            }
            
            if(correct==word.length()){
                winStatus.setText("You Win!");
                buttons.setDisable(true);
            }
        }
        else{
            mistakes++;
            if(mistakes ==1)       base1.setVisible(true);
            else if (mistakes ==2) base2.setVisible(true);
            else if (mistakes ==3) base3.setVisible(true);
            else if (mistakes ==4) pole.setVisible(true);
            else if (mistakes ==5) rod.setVisible(true);
            else if (mistakes ==6) rope1.setVisible(true);
            else if (mistakes ==7) rope2.setVisible(true);
            else if (mistakes ==8){
                rope2.setVisible(false); //7bal lmachan9a around the neck 
                man.setVisible(true);//sad face+body
                winStatus.setText("You Lose!");
                realWord.setText("The actual word was " + word);
                buttons.setDisable(true);
            }
        }
    }

    public void newGame(){
        //i don't get what does the loops does
        //why enable here and enable in initialize?
        for(int i=0; i<26; i++){
            buttons.getChildren().get(i).setDisable(false);
        }
        initialize();
    }


}
package sample;

import java.util.Random;

public class Words{
    
       
    public static String[] getRandomWord(int languageChoice) {
        
        String[] fruits = {"strawberry", "banana", "orange", "apple", "cherry", "peach", "kiwi", "lemon", "grape", "mango"};
        String[] countries = {"tunisia", "spain", "japan", "qatar", "greece", "palestine", "italy", "canada", "germany", "china"};
        String[] animals = {"shark", "wolf", "cat", "cow", "snake", "horse", "dog", "lion", "rabbit", "zebra"};
        String[] languages = {"arabic", "korean", "english", "russian", "turkish", "hindi", "spanish", "french", "german", "chinese"};
        String[] occupations = {"doctor", "engineer", "teacher", "baker", "clown", "pilot", "lawyer", "chef", "nurse", "police"};

        String[] fruit = {"fraise", "bananes", "orange", "pomme", "cerise", "pêche", "kiwi", "citron", "raisin", "mangue"};
        String[] pays = {"tunisie", "espagne", "japon", "qatar", "grèce", "palestine", "italie", "canada", "allemagne", "chine"};
        String[] animaux = {"requin", "loup", "chat", "vache", "serpent", "cheval", "chien", "lion", "lapin", "zèbre"};
        String[] langues = {"arabe", "coréen", "anglais", "russe", "turc", "hindi", "espagnol", "français", "allemand", "chinois"};
        String[] professions = {"médecin", "ingénieur", "enseignant", "boulanger", "clown", "pilote", "avocat", "chef", "infirmier", "police"};
        
        String category=null;
        String word=null;      
        int categoryIndex = new Random().nextInt(5)+1; 

        if (languageChoice == 2) {
            switch (categoryIndex) {
                case 1:
                    category = "fruits";
                    word = fruits[new Random().nextInt(fruits.length)];
                    break;
                case 2:
                    category = "countries";
                    word = countries[new Random().nextInt(countries.length)];
                    break;
                case 3:
                    category = "animals";
                    word = animals[new Random().nextInt(animals.length)];
                    break;
                case 4:
                    category = "languages";
                    word = languages[new Random().nextInt(languages.length)];
                    break;
                case 5:
                    category = "occupations";
                    word = occupations[new Random().nextInt(occupations.length)];
                    break;
            }
        } 
        else {
            switch (categoryIndex) {
                case 1:
                    category = "fruits";
                    word = fruit[new Random().nextInt(fruit.length)];
                    break;
                case 2:
                    category = "pays";
                    word = pays[new Random().nextInt(pays.length)];
                    break;
                case 3:
                    category = "animaux";
                    word = animaux[new Random().nextInt(animaux.length)];
                    break;
                case 4:
                    category = "langues";
                    word = langues[new Random().nextInt(langues.length)];
                    break;
                case 5:
                    category = "professions";
                    word = professions[new Random().nextInt(professions.length)];
                    break;
            }
        }

        return new String[]{category, word};
    }
} ```

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật