Help me please! class problems

J

Jens Friedrich

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
 
A

Andrew Thompson

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..
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]
...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..
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?
 
P

Phillip Mills

Jens Friedrich said:
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....
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top