Versuche vergeblich eine java paint() methode von der Hauptklasse aus anzustoßen.
Welcher Befehl in der Hauptklasse bewirkt die Ausführung der public void paint(Graphics g){} Methode aus der Unterklasse?
Vielen Dank im Voraus
Hauptklasse:
Unterklasse:
Welcher Befehl in der Hauptklasse bewirkt die Ausführung der public void paint(Graphics g){} Methode aus der Unterklasse?
Vielen Dank im Voraus
Hauptklasse:
Java:
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class MeineStrasseBasis extends Applet {
public void init() {
setBackground(Color.BLUE);
resize(300, 200);
}
}
Unterklasse:
Java:
import java.awt.Color;
import java.awt.Graphics;
public class Haus extends MeineStrasseBasis {
private int xPos;
private int yPos;
private int hoehe;
private int breite;
private Color mauerFarbe;
private boolean lichtAn;
public Haus(int xPos, int yPos, int hoehe, int breite, Color mauerFarbe) {
setHaus(xPos, yPos, hoehe, breite, mauerFarbe);
}
public void setHaus(int xPos, int yPos, int hoehe, int breite,
Color mauerFarbe) {
if (xPos >= 0) {
this.xPos = xPos;
if (yPos >= 0) {
this.yPos = yPos;
}
if (hoehe > 0) {
this.hoehe = hoehe;
}
if (breite > 0) {
this.breite = breite;
}
}
this.mauerFarbe = mauerFarbe;
}
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(mauerFarbe);
g.fillRect(xPos, yPos, breite, hoehe);
g.setColor(c);
}
public void start() {
// erzeugt ein Feld für 4 Häuser
Haus[] hausArray = new Haus[3];
hausArray[0] = new Haus(230, 140, 50, 40, Color.DARK_GRAY);
hausArray[1] = new Haus(30, 120, 50, 60, Color.WHITE);
hausArray[2] = new Haus(140, 100, 70, 80, Color.yellow);
}
}