I am just starting to learn Java and I am using text pad when I try to compile an applet it gives me these errors and according to the book they should not be errors. Unless I am missing something?
Here is the code and errors:
/*
Chapter 2: Welcome to My Day
Programmer: Dickie Taylor
Date: October 4, 2007
Filename: WelcomeApplet.java
Purpose: This project displays a welcome message, the user's
name, and the system date in a console application.
*/
public class WelcomeApplet
{
public void paint(Graphics g)
{
Date currentDate = new Date(); //Date constructor
g.drawString("Welcome to my day!",200,70);
g.drawString("Daily planner for Dickie Taylor",200,100);
g.drawString(currentDate.toString(),200,130);
Image smile; //declare an Image object
smile = getImage( getDocumentBase(),"Smile.gif");
g.drawImage(smile,10,10,this);
setBackground(Color.cyan);
}
}
ERRORS are:
C:\Java\Chapter 2\WelcomeApplet.java:23: cannot find symbol
symbol : method getDocumentBase()
location: class WelcomeApplet
smile = getImage( getDocumentBase(),"Smile.gif");
^
C:\Java\Chapter 2\WelcomeApplet.java:24: cannot find symbol
symbol : method drawImage(java.awt.Image,int,int,WelcomeApplet)
location: class java.awt.Graphics
g.drawImage(smile,10,10,this);
^
C:\Java\Chapter 2\WelcomeApplet.java:25: cannot find symbol
symbol : method setBackground(java.awt.Color)
location: class WelcomeApplet
setBackground(Color.cyan);
^
3 errors
Tool completed with exit code 1
Any help would be very much appreciated.
Thank You,
DLT
09-07-2007, 12:58 AM
nspils
What class is supposed to supply you the getImage, drawImage, and setBackground methods?
You need to invoke a class's method directly. If the method is not static (with a static class you would invoke ClassName.methodName(arg)) you must have an instance of the class created and you must invoke that's instance's method.
It looks to me that you are missing a big piece of this Applet.
09-07-2007, 05:31 PM
dltaylor
I am trying to simply create an applet that is going to have a graphic and says welome and another sentence and gives the system Date?
09-08-2007, 09:56 AM
nspils
Are you taking a class? Doesn't your text book have more information about how to build an Applet and to exploit the graphics environment? Take a look at the Java Tutorial on Applets at
among the many resources available on the Internet.
One of the first things you must do with your code is for your WelcomeApplet to be an "applet" by inheriting from java.awt.Applet. So, you must declare your class using:
public class WelcomeApplet extends Applet
this may give you access to the methods you want to use since those methods are members of the Applet class, either directly or inherited from the java.awt.Component class.
09-08-2007, 05:36 PM
Armaron
Your operator (don't know if it's the right name) "g" should be dimensionalised. Like "Private String g;", but that seems to be missing. That "g" also needs to have the functions getImage, drawImage and setBackground.
09-08-2007, 06:32 PM
nspils
g is the Graphics environment of the Applet container
09-12-2007, 10:05 AM
cloud4288
some of the methods you've used are part of the Applet class...
to make your code compile correct, just extend your class to the Applet class...