aspose file tools*
The moose likes Beginning Java and the fly likes Applet Frustration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Applet Frustration" Watch "Applet Frustration" New topic
Author

Applet Frustration

Greg Roberts
Ranch Hand

Joined: Feb 05, 2005
Posts: 72
I am trying to write an applet that draws a face. Basically a filled circle, with drawn circles for eyes and nose. I haven't gotten to the mouth yet as I'm having some errors I can't seem to resolve.

In the line "Graphics2D g2 = (Graphics2D)g;" I'm getting "Cannot resolve symbol" and in the line "newFace.draw();" I'm getting "draw(java.awt.Graphics2D) in Face cannot be applied to ()" I've also got tons of other "Cannot resolve symbol" errors (I put comments where they appear as CRS, Symbol .

Here's the code:

FaceApplet.java


Face.java (class file)

[ February 24, 2005: Message edited by: Greg Roberts ]

Greg Roberts<br />CIS Student<br />University of West Florida
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8707
    
    6

"Cannot resolve symbol" means exactly what it says. The compiler cannot find the variable or method you are using. For example:

Where's the variable "g" declared? You have to declare it before you use it.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Greg Roberts
Ranch Hand

Joined: Feb 05, 2005
Posts: 72
g is not a variable. Its part of (Graphics2D)g. At least that's what I assumed. I'm not trying to use a variable called "g" in my program, I thought it was just part of using Graphics2D.
[ February 24, 2005: Message edited by: Greg Roberts ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8707
    
    6

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.
Greg Roberts
Ranch Hand

Joined: Feb 05, 2005
Posts: 72
Trust me, I'm not striking out on my own here. This is a project for an introductory Java class. Here are the instructions for the project:

Project Requirements:
1. Write a program that draws a Face. There should be a Face.java file that contains the actual code for the Face Class. This Face class should have a method that looks like this:
public void draw(Graphics2D g)
{
... // much code here...
}
This will allow your Face class to draw itself. It should also have a constructor that looks like this:
public Face(double aFaceRadius, Color aFillColor)

This constructor will allow your Face to be drawn of any size and any color.

2. You should also have a FaceApplet.java file that extends the Applet class. This is the program that you will run and display an instance of your Face class
In this class you will have a:
a. paint method that will call the draw method of your face class.
b. constructor that will use the dialog boxes to get the radius and color of the face. (see ColorApplet.java pg 164 - 165 of Big Java).

3. You should also have a FaceApplet.html file that links to the Applet class using the <applet> tag. For example:
<applet code="FaceApplet.class" width="200" height="300"> </applet>

4. Your Face must have at least 4 components such as a set of eyes, a nose and a mouth with turn-up edges and a color. You can make it look however you wish, but try to make it interesting. Once you get the minimum requirements completed you may want to try adding ears or a hat etc.


Also, I updated my code and got it down to 1 error message. Here's the updated version:


Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8707
    
    6

There's a difference between a method declaration, for example:

and a method invocation, for example:

In the declaration we tell the compiler what the arguments of the method are, both the type and a variable name. In a method invocation we just pass the variable(s). Given that difference, there's something wrong with this method invocation (a constructor is a special type of method invocation):
Greg Roberts
Ranch Hand

Joined: Feb 05, 2005
Posts: 72
I'm sorry, but I don't understand how that helps me. I don't fully understand the Graphics class, which I need to make this project work. Can you recommend a good tutorial on the Graphics class? I'll post my code again with the errors I'm getting.





[ February 26, 2005: Message edited by: Greg Roberts ]

[ February 26, 2005: Message edited by: Greg Roberts ]
[ February 26, 2005: Message edited by: Greg Roberts ]
 
Don't get me started about those stupid light bulbs.
 
subject: Applet Frustration
 
Similar Threads
Help with project using graphics
Graphics2D compiler error
Debugging
Applet to draw Ellipse
Graphics2D and Math classes in an Applet