Originally posted by Greg Roberts:
g is not a variable.
Trust me: Don't argue with the
Java compiler. It's not going to change its mind.
You MUST declare variables before you use them. The statement:
is called a "type cast". It takes a variable of one type (g is supposed to be declared as type Graphics) and turns it into another type, in this case, Graphics2D.
What you are actually trying to do is override the method Applet.paint() which is inherited from Component. It's method signiture looks like this:
The "g" in that method signiture is what you are trying to manipulate.
What's more, since your method paint doesn't override Component's paint signiture (i.e. the signitures must be identical), your method would never get called by the JVM's display engine.
I
strongly suggest that you work your way through the
Java Tutorial before you strike out on your own. There's a lot to Java. Having a good foundation in the basics will save you a lot of pain.