Save multiple Letters

Hey I’m new,

Our teacher askes us to develope a learning programm for the scrabble game. Basically you get 9 letter from which you can wright a word, that word is then checkedm to see if it is in the Library.

I can already test if a word is valid in the static mode, but I’m at a loss in the active mode. Is there any way to save multiple pressed kesy to a String or Array? My head’s been spinng for the last couple days.

Thanks in advance for any hints :slight_smile:

1 Like

Storing states for all keys with a dynamically increasing data set can be pretty tricky. One thing I once did is to use a Table, add new columns for previously unknown keys using Keys.addColumn(key);, and store either 0 or 1 for each key using Keys.setInt(0,key,1); or Keys.setInt(0,key,0); inside of keyPressed() and keyReleased() respectively.

However, in your case, I think the easiest way would be to first store your 9 letters in a char[] array, and then make a button for each one of them that you can press only once to add a letter at the end of a String that is your result - with a “Reset” button that resets all buttons and that String, and a “Check” button that checks if the word is in there or not.
For simplicity, I suggest making a second boolean[] array to store states of all buttons. However, if you are familiar with classes, you might as well make a class for one letter that contains the letter itself and its button’s state.

1 Like

Thanks for the tip, it inspired a solution.
I now saved them in a arrayList, not the most elegent way but it works

Now i just have to get rid ob a nullpointer exception and im good to go…