Du solltest wenigstens die Fehlermeldung hier posten, sowie den Code-Teil, in dem die Fehlermeldung ausgelöst wurde.
Ganze Programme kannst du auch posten, wenn sie nicht zu groß sind. Besser sind aber Minimalbeispiele, in denen du deinen Code auf das für die Fragestellung wesentliche kürzt.
folgende Fehlermeldung kommt beim Übersetzen der Quellecodes:
method zeigen in class Roboter cannot be given to types;
required: java.awt.Graphics,int,int,java.awt.Color;
found: java.awt.Graphics,java.awt.Color;
reason: actual and formal argument lists differ in lenght;
Klasse Roboter
[Java]
import java.awt.*;
import java.awt.Color.*;
public class Roboter
{
int xPos, yPos;
int richtung;
int geschwindigkeit;
public Roboter(int x, int y)
{
xPos = x;
yPos = y;
richtung = 1;
geschwindigkeit = 50;
}
public void zeigenVorn(Graphics g, int x, int y)
{
g.drawRect( xPos, yPos,50,50); // Kopf
g.drawRect( xPos+10,yPos+ 50,30,30); // Hals
g.drawRect( xPos-20,yPos+ 80,90,90); // Rumpf
g.drawRect( xPos-10,yPos+170,20,40); // linkes Bein
g.drawRect( xPos+40,yPos+170,20,40); // rechtes Bein
g.drawRect( xPos-40,yPos+ 80,20,60); // linker Arm
g.drawRect( xPos+70,yPos+ 80,20,60); // rechter Arm
g.drawOval( xPos+10,yPos+ 10,14,14); // linkes Auge
g.drawOval( xPos+26,yPos+ 10,14,14); // rechtes Auge
g.drawOval( xPos+10,yPos+ 35,30, 6); // Mund
}
public void zeigenHinten(Graphics g, int x, int y)
{
g.drawRect( xPos, yPos,50,50); // Kopf
g.drawRect( xPos+10,yPos+ 50,30,30); // Hals
g.drawRect( xPos-20,yPos+ 80,90,90); // Rumpf
g.drawRect( xPos-10,yPos+170,20,40); // linkes Bein
g.drawRect( xPos+40,yPos+170,20,40); // rechtes Bein
g.drawRect( xPos-40,yPos+ 80,20,60); // linker Arm
g.drawRect( xPos+70,yPos+ 80,20,60); // rechter Arm
g.drawOval( xPos+10,yPos+130,30,30); // Steckdose
g.drawOval( xPos+13,yPos+140,10,10); // Steckdose
g.drawOval( xPos+27,yPos+140,10,10); // Steckdose
}
public void zeigenLinks(Graphics g, int x, int y)
{
g.drawRect(xPos ,yPos, 30,50); // Kopf
g.drawRect(xPos+ 5,yPos+ 50,20,30); // Hals
g.drawRect(xPos-10,yPos+ 80,50,90); // Rumpf
g.drawRect(xPos+ 5,yPos+170,20,40); // Beine
g.drawRect(xPos, yPos+ 80,20,60); // linker Arm
g.drawRect(xPos+30,yPos+ 10, 5,14); // Augen
}
public void zeigenRechts(Graphics g, int x, int y)
{
g.drawRect(xPos ,yPos, 30,50); // Kopf
g.drawRect(xPos+ 5,yPos+ 50,20,30); // Hals
g.drawRect(xPos-10,yPos+ 80,50,90); // Rumpf
g.drawRect(xPos+ 5,yPos+170,20,40); // Beine
g.drawRect(xPos+10,yPos+ 80,20,60); // rechter Arm
g.drawRect(xPos- 5,yPos+ 10, 5,14); // Augen
}
public void linksUm(Graphics g)
{
zeigen(g,Color.WHITE);
if (richtung < 4) richtung++;
else richtung = 1;
zeigen(g.Color.BLACK);
}
public void vor(Graphics g)
{
zeigen(g,Color.WHITE);
if ((richtung == 2) && (x <= 400)) // nach rechts - von uns aus gesehen
x += geschwindigkeit;
else if ((richtung == 4)&& (x >= 50)) // nach links
x -= geschwindigkeit;
zeigen(g,Color.BLACK);
}
public void schneller()
{
if (geschwindigkeit <= 100)
geschwindigkeit += 10;
}
public void langsamer()
{
if (geschwindigkeit >= 10)
geschwindigkeit -= 10;
}
public void zeigen(Graphics g, int x, int y, Color Black)
{
if (richtung == 1) zeigenVorn(g,x,y);
else if (richtung == 2) zeigenRechts(g,x,y);
else if (richtung == 3) zeigenHinten(g,x,y);
else if (richtung == 4) zeigenLinks(g,x,y);
}
}
[/Java]
JApplet Territorium
[Java]
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Territorium extends JApplet implements ActionListener
{
Roboter robbi;
Button btnVor, btnLinks, btnPlus, btnMinus;
public void init()
{
robbi = new Roboter(50,100);
btnVor = new Button("Vor");
btnLinks = new Button("Links Um");
btnPlus = new Button("+");
btnMinus = new Button("-");
add(btnVor);
add(btnLinks);
add(btnPlus);
add(btnMinus);
setLayout(null);
btnLinks.setBounds(140,420,100,50);
btnVor.setBounds(240,420,100,50);
btnPlus.setBounds(340,420,50,50);
btnMinus.setBounds(390,420,50,50);
btnLinks.addActionListener(this);
btnVor.addActionListener(this);
btnPlus.addActionListener(this);
btnMinus.addActionListener(this);
}
public void actionPerformed(ActionEvent ereignis)
{
if (ereignis.getSource() == btnLinks)
robbi.linksUm(getGraphics());
if (ereignis.getSource() == btnVor)
robbi.vor(getGraphics());
if (ereignis.getSource() == btnPlus)
robbi.schneller();
if (ereignis.getSource() == btnMinus)
robbi.langsamer();
}
public void paint(Graphics g)
{
robbi.zeigen(g,Color.BLACK);
}
}
[/Java]