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.

As you use Swing more, you'll get more and more familiar with its inheritance hierarchy. For instance you'll learn that most visible components inherit from JComponent. So knowing that JLabel is derived from JComponent, if when you search the API you don't find a way to set a property you're interested in setting, then your next step is to check the API for the ancestor -- the JComponent. If you do this, you'll find the method setForeground(Color fg) which will allow you to change the color of all the text on that JLabel. Now to change the individual text on a JLabel, I think that you may need to use HTML. Another way to solve this is to use an array of JLabel, each holding exactly one letter, and then changing the foreground on the individual label corresponding to your letter (a Map<String, JLabel> comes to mind here).

Wow man that is a genius idea. I learned about maps/sets/linkedlists two chapters ago but I never would've remembered to use it for this problem. I'm definitely going to do that. Thanks. What's your background in programming? Seems like you know everything there is to know about java.

Is there anyway to use Graphics to draw text char by char?
Yes, probably a lot of ways. You can have a lot more control/subtlety with graphics but it means more work/details to look after. The main advantages are in layout/placement and behavior. There are a few tricks that can ease the way but these usually seem to come with experience or example. Such as the hit–testing for the letters in this:

HardWired code is pretty slick. And as he mentioned, there are many ways to solve this problem, but just for comparison, here's a way to do the same thing without using Graphics but instead using an array of JLabels, each holding a different letter and each accepting a mouse press.