I write the game "Balda". I plan to create 5x5, each cell is a separate JTextField. Gameplay: irok_1 move - enters 1 letter, after which input into the remaining JTextField is blocked, clicking on individual cells selects a word, after which player_2 allows the given word or not, etc. (see the screen, two buttons below)

I do not know how to do the following: locking and unlocking the JTextField, and selecting specific letters to create a word.

enter image description here

Main class ; The game field (array to store letters) ; Player

  • one
    tried - yourJTextField.setEditable(false) ? (this is for locking / unlocking) - Vladislav Zherikhov
  • No, now I will try - O.Mazuruk
  • yes, thanks, this solves my problem - O.Mazuruk

1 answer 1

 // создание текстового поля JTextField jTextField_enter = new JTextField(); jTextField_enter.getDocument().addDocumentListener(new DocumentListener() { // этот метод будет выполняться при вводе нового символа @Override public void insertUpdate(DocumentEvent e) { // запрет редактирования текстового поля jTextField_enter.setEditable(false); } @Override public void removeUpdate(DocumentEvent e) {} @Override public void changedUpdate(DocumentEvent e) {} });