Help me please! class problems

Discussion in 'Java' started by Jens Friedrich, Sep 9, 2004.

  1. Hi look @ this code:


    mapper.java:
    -------------

    import java.applet.*;
    import java.awt.*;

    public class mapper extends Applet
    {
    public void paint (Graphics g)
    {

    if(bild.isLoadedID(id))
    {
    bild.showImage(id,0,0,400,400,g);
    }
    else
    {
    g.drawString("loading",50,50);
    }
    }
    }


    OrgImage.java:
    ----------------

    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.MediaTracker;

    public class OrgImage
    {
    int MAX=10;
    MediaTracker tracker;
    Image test;

    OrgImage()
    {
    this.image = new Image[MAX];
    this.tracker = new MediaTracker(this); //ERROR1
    }

    int addImage(String source)
    {
    this.ID++;
    this.test = this.getImage(getCodeBase(), source); //ERROR2
    return this.ID;
    }

    }



    Both files are in one directory im working with Eclipse 3.0

    ERROR1: The constructor MediaTracker(OrgImage) is undefined
    ERROR2: The method getCodeBase() is undefined for the type OrgImage

    Please help

    MfG
    Stylistics
     
    Jens Friedrich, Sep 9, 2004
    #1
    1. Advertising

  2. On Thu, 9 Sep 2004 12:45:17 +0200, Jens Friedrich wrote:


    > Sub: Help me please! class problems


    Hi Jens, there are a number of different Java
    newsgroups, I describe most of the best ones here..
    <http://www.physci.org/codes/javafaq.jsp#cljh>

    c.l.j.help is specially set-up to help
    people who are starting in Java, you might
    consider posting there for the moment, I
    feel it will give you better value.

    > Hi look @ this code:


    OoooK..

    I will replace your code with my own (slightly)
    better version that has only nine compile errors,
    you will need to put some more work into it yet
    before it will compile.

    For tips on preparing code for others to see, check here..
    <http://www.physci.org/codes/sscce.jsp>

    > mapper.java:
    > -------------

    import java.applet.*;
    import java.awt.*;

    /** Class names should start each
    word with UpperCase. */
    public class Mapper extends Applet
    {

    public void paint (Graphics g)
    {
    /* what is 'bild'/'id'! neither is
    defined in this code, neither are
    they attributes of the Applet class. */
    if(bild.isLoadedID(id))
    {
    // what is 'id'! it is not defined in this code..
    bild.showImage(id,0,0,400,400,g);
    }
    else
    {
    g.drawString("loading",50,50);
    }
    }
    }

    /** Tip - if you leave this as a 'default' access
    class it can be compiled in the same file as Mapper,
    great for making an SSCCE. */
    class OrgImage
    {
    int MAX=10;
    MediaTracker tracker;

    /* 'test' was a bad name for an attribute,
    especially since you refer to it as 'image' below..
    as well, you use it as an array below, (0-n images),
    where Image image is a single instance, either you need
    both an array and a single image, or you only need one
    or the other, please figure which, and declare it.. */
    Image image;

    /** declare and inititalise the ID counter. */
    public static int ID = 0;

    OrgImage()
    {
    // the Image was named 'test'
    this.image = new Image[MAX];
    this.tracker = new MediaTracker(this); //ERROR1
    /* ERROR1? I get a total of 9 compile errors
    in your original code. */
    }

    int addImage(String source)
    {
    // again, you need to *define* ID..
    this.ID++;
    /* getCodeBase [1] is a method of the applet class,
    where this code extends Object, so it cannot
    be accessed from this class. */
    this.test = this.getImage(getCodeBase(), source); //ERROR2
    return this.ID;
    }
    }

    [1]
    <http://java.sun.com/j2se/1.4.2/docs/api/java/applet/Applet.html#getDocumentBase()>

    > ...im working with Eclipse 3.0


    Eclipse is neither the problem
    *nor* the solution here.

    You need to be able to figure out how to
    use the command line before you let an
    IDE do things for you..
    <http://www.xdweb.net/~dibblego/java/faq/answers.html#q34>

    > ERROR1: The constructor MediaTracker(OrgImage) is undefined
    > ERROR2: The method getCodeBase() is undefined for the type OrgImage


    Your code indicates to me that you have very
    little idea of what you are doing.

    How many classes have you compiled and run?
    Have you successfully done a 'HelloWorld'
    example?

    If you are prepared to shift this over to
    c.l.j.help, I can help you further, but
    before I sign off this thread, I will add..

    It might be best in this situation to
    add the information of ..
    a) what do you start with?
    b) what do you want to achieve?
    That is not clear from your code.

    So.. see you over on c.l.j.help, with a
    better example and more clearly stated goals?

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Sep 9, 2004
    #2
    1. Advertising

  3. In article <>,
    "Jens Friedrich" <> wrote:

    > public class OrgImage
    > {


    [...]

    > ERROR1: The constructor MediaTracker(OrgImage) is undefined


    The MediaTracker constructor wants to be given some kind of Component.
    OrgImage does not inherit from Component.

    > ERROR2: The method getCodeBase() is undefined for the type OrgImage


    The method getCodeBase is defined for an Applet, but OrgImage does not
    inherit from Applet.

    You need these calls to be within your mapper class, or you need a
    reference to a mapper passed to OrgImage, or....

    --
    Phillip Mills
    Multi-platform software development
    (416) 224-0714
     
    Phillip Mills, Sep 9, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    571
    Chris Uppal
    May 5, 2005
  2. E11
    Replies:
    1
    Views:
    4,955
    Thomas Weidenfeller
    Oct 12, 2005
  3. KK
    Replies:
    2
    Views:
    735
    Big Brian
    Oct 14, 2003
  4. MuZZy
    Replies:
    7
    Views:
    1,830
    Mike Hewson
    Jan 7, 2005
  5. drawing in aspnet
    Replies:
    0
    Views:
    351
    drawing in aspnet
    May 11, 2007
Loading...

Share This Page