drawing char by char with Graphics
Hey guys... I just started brainstorming for my hangman project today. The exercise which I'm basing the project on shows the game as a GUI with a big white area with the picture taking the top 2/3 and below it is the chosen word which gradually appears with each correctly guessed letter, and below that is the entire alphabet. Each guessed letter in the displayed alphabet turns grey upon being guessed.
At first, I had thought of a way to do this - I wanted to use a JLabel to display the word and the alphabet. I planned to set the word's color to white, and change the font of each correctly guessed letter to black, thus slowly displaying them.
I also was gonna do the same for the alphabet, changing each guessed letter to grey.
However, I've been looking through all the API's and I don't see how I could change the font color in JLabel, let alone that of a single character in the label. The image on the exercise of the completed program shows the letter and alphabet in the same white square as the picture of the hangman, so I thought perhaps I'd draw the letters onto the image panel. But the only methods for drawing letters that I saw were the one that drew the character array and the one that drew a string. Using these methods, I could update an array of chars based on whether or not each char was chosen and go through this array and redraw and use an if statement for each value in the array to determine the color. But I've been reading about program efficiency and it seems a lot more efficient to simply develop a method to locate the single letter that was chosen and change that one's color, rather than redraw every single one after every guessed letter.
So my two questions are as follows:
1) Just for future reference - how can I change the font color for a JLabel? I looked through the API's for font AND JLabel and I couldn't find anything color-related.
2) It looks like the drawChar method draws everything in a single go and doesn't allow you to change the color of individual chars, or the spacing between the letters. This is what it looks like from the API anyway. Is there anyway to use Graphics to draw text char by char? I can't seem to find it... If I can do this, I don't think I'd have much trouble finishing the rest of my program.