-
error Help!
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.
*/
import java.util.Date;
import java.awt.*;
import java.applet.*;
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
-
What class is supposed to supply you the getImage, drawImage, and setBackground methods?
-
classes are
import java.util.Date;
import java.awt.*;
import java.applet.*;
-
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.
-
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?
-
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
http://java.sun.com/docs/books/tutor...let/index.html
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.
-
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.
-
g is the Graphics environment of the Applet container
-
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks