Re: Frustrated by AWT..need some help
Here's a piece of code that I borrowed from another site and made to
show my traffic light.
I respect what you are trying to do here; your on-going efforts to
learn Java are very admirable. However, that AWT code you posted hurted
my brain. AWT isn't really the default graphic interface anymore. It's
good to know it exists if you have to do anything really complicated,
but I wouldn't recommend someone start their Java career by learning it.
Check up Sun's (current) guide to learning their latest graphic API, Swing:
Notice at the beginning of that page, it says, "This is a pain in the
neck; use Matisse?" Do that. Get Netbeans, get Matisse (I think
Matisse comes with NetBeans by default now) and learn to lay out a
simple little JFrame with Matisse.
(Notice also that if you are at the link I posted, click on "Trail" at
the top of the page, you'll be taken to the table of contents which
starts with an intro to Matisse.)
Put four buttons on your JFrame, one for each traffic light, then learn
how to set an Icon in each button to represent the state of your traffic
light. The Icon should have one lighted circle on it for each state,
red, green and yellow. You'll need to switch the Icons around at run
time to show the state of your running program, that'll be something you
can't do directly with Matisse.
AWT is good to learn eventually, but Matisse or a similar GUI builder is
the correct answer for 90% of the code you will ever write, and AWT will
be much easier once you have a firmer foundation in the fundamentals.
Right now you're really banging your head against a wall for little result.