Hallo
Ich möchte mit einem Freund ein kleines Auto spiel machen.
Wir sind schon soweit das ein kleines Auto aus Rechtecken fahren kann.
Nun wollen wir aber diese rechteckkonstruktion durch ein bild ersetzen.
Hier die Auto Methode:
[HIGHLIGHT="Java"]import java.awt.*;
import java.*;
/**
* @author schueler1
*
*/
public class Auto{
int h1, h2, b1, b2, d;
int x, y;
Image autoRechts=getImage(getDocumentBase(),"auto_rechts.jpg");
Image autoLinks;
Image autoRunter;
Image autoHoch;
Color farbe = Color.BLUE;
Auto(int x0, int y0) {
x = x0;
y = y0;
h1 = 8;
h2 = 5;
b1 = 25;
b2 = 35;
d = 5;
}
void vorwaerts(int v) {
x = x + v;
}
void runter(int r) {
y = y + r;
}
void maleAuto(Graphics g) {
g.setColor(farbe);
g.drawRect(x, y, b1, h1);
g.fillRect(x, y + h1, b2, h2);
g.drawOval(x + d, y + h1 + h2, d, d);
g.drawOval(x + b2 - 2 * d, y + h1 + h2, d, d);
}//hier wird das alte Auto gezeichnet
}[/HIGHLIGHT]
Nun wird aber bei
Image autoRechts=getImage(getDocumentBase(),"auto_rechts.jpg");
das getDocumentBase() unterschlängelt mit der Meldung:
The method getDocumentBase() is undefined for the type Auto
Ich hoffe ihr könnt mir helfen
Ich möchte mit einem Freund ein kleines Auto spiel machen.
Wir sind schon soweit das ein kleines Auto aus Rechtecken fahren kann.
Nun wollen wir aber diese rechteckkonstruktion durch ein bild ersetzen.
Hier die Auto Methode:
[HIGHLIGHT="Java"]import java.awt.*;
import java.*;
/**
* @author schueler1
*
*/
public class Auto{
int h1, h2, b1, b2, d;
int x, y;
Image autoRechts=getImage(getDocumentBase(),"auto_rechts.jpg");
Image autoLinks;
Image autoRunter;
Image autoHoch;
Color farbe = Color.BLUE;
Auto(int x0, int y0) {
x = x0;
y = y0;
h1 = 8;
h2 = 5;
b1 = 25;
b2 = 35;
d = 5;
}
void vorwaerts(int v) {
x = x + v;
}
void runter(int r) {
y = y + r;
}
void maleAuto(Graphics g) {
g.setColor(farbe);
g.drawRect(x, y, b1, h1);
g.fillRect(x, y + h1, b2, h2);
g.drawOval(x + d, y + h1 + h2, d, d);
g.drawOval(x + b2 - 2 * d, y + h1 + h2, d, d);
}//hier wird das alte Auto gezeichnet
}[/HIGHLIGHT]
Nun wird aber bei
Image autoRechts=getImage(getDocumentBase(),"auto_rechts.jpg");
das getDocumentBase() unterschlängelt mit der Meldung:
The method getDocumentBase() is undefined for the type Auto
Ich hoffe ihr könnt mir helfen
Zuletzt bearbeitet von einem Moderator: