error Help!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: error Help!

  1. #1
    Join Date
    Sep 2007
    Posts
    7

    Unhappy 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

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    What class is supposed to supply you the getImage, drawImage, and setBackground methods?

  3. #3
    Join Date
    Sep 2007
    Posts
    7

    classes are

    import java.util.Date;
    import java.awt.*;
    import java.applet.*;

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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.

  5. #5
    Join Date
    Sep 2007
    Posts
    7
    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?

  6. #6
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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.

  7. #7
    Join Date
    May 2007
    Posts
    59
    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.

  8. #8
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    g is the Graphics environment of the Applet container

  9. #9
    Join Date
    Jan 2006
    Location
    Lourdes, Lubao, Pampanga, Philippines
    Posts
    36
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center