Hi!
Ich hoff, ich geh niemandem auf die Nerven!
Ich hab schon wieder ein kleines Verständnisproblem!
3 Klassen:
eine Hauptklasse: Spielball
eine Klasse Circle
eine Klasse Rect
Jetzt ist mein Problem, dass ich, wenn ich beide Klassen aus Spielball aufruf, ich entweder nur den Kreis oder eben das Rechteck seh!
Wie funktioniert das aber, dass ich beide seh..sprich, dass das Rechteck um den Kreis gelegt wird...??
Ich möchte nämlich dann den Kreis zwischen den Begrenzunglinien des Rechtecks hin-und herlaufen lassen!Wenn er eine Begrenzungslinie erreicht, soll der Kreis in die andere Richtung laufen...!
Hat jemand eine Idee?
Es wär echt sehr wichtig für mich, denn das Problem hab ich immer wieder!
Könnte es an dem Layout-Manager liegen?
Wie könnte man das sonst machen?
[/code]public class Spielball extends JApplet{
Container c;
Circle circle1;
Rect rect1;
Thread runner;
public void init(){
c=getContentPane();
c.setLayout(new BorderLayout());// Mit FlowLayout gehts auch nicht
c.setBackground(Color.red);
rect1=new Rect(500,500);
circle1=new Circle(250,140,10);
c.add(rect1,BorderLayout.CENTER);
c.add(circle1,BorderLayout.CENTER);
}
}
class Circle extends JComponent {
private int xpoint;
private int ypoint;
private int radius;
public Circle(int xpoint,int ypoint,int radius){
this.xpoint=xpoint;
this.ypoint=ypoint;
this.radius=radius;
setBounds(xpoint,ypoint,radius,radius);
}
public void paint(Graphics g){
g.fillOval(xpoint,ypoint,radius,radius);
}
}
public class Rect extends JComponent{
int x_final;
int y_final;
public Rect(int x_final, int y_final){
this.x_final=x_final;
this.y_final=y_final;
}
public void paint(Graphics g){
g.setColor(Color.black);
g.drawRect(0,0,x_final,y_final);
}
}
Ich hoff, ich geh niemandem auf die Nerven!
Ich hab schon wieder ein kleines Verständnisproblem!
3 Klassen:
eine Hauptklasse: Spielball
eine Klasse Circle
eine Klasse Rect
Jetzt ist mein Problem, dass ich, wenn ich beide Klassen aus Spielball aufruf, ich entweder nur den Kreis oder eben das Rechteck seh!
Wie funktioniert das aber, dass ich beide seh..sprich, dass das Rechteck um den Kreis gelegt wird...??
Ich möchte nämlich dann den Kreis zwischen den Begrenzunglinien des Rechtecks hin-und herlaufen lassen!Wenn er eine Begrenzungslinie erreicht, soll der Kreis in die andere Richtung laufen...!
Hat jemand eine Idee?
Es wär echt sehr wichtig für mich, denn das Problem hab ich immer wieder!
Könnte es an dem Layout-Manager liegen?
Wie könnte man das sonst machen?
[/code]public class Spielball extends JApplet{
Container c;
Circle circle1;
Rect rect1;
Thread runner;
public void init(){
c=getContentPane();
c.setLayout(new BorderLayout());// Mit FlowLayout gehts auch nicht
c.setBackground(Color.red);
rect1=new Rect(500,500);
circle1=new Circle(250,140,10);
c.add(rect1,BorderLayout.CENTER);
c.add(circle1,BorderLayout.CENTER);
}
}
Code:
private int xpoint;
private int ypoint;
private int radius;
public Circle(int xpoint,int ypoint,int radius){
this.xpoint=xpoint;
this.ypoint=ypoint;
this.radius=radius;
setBounds(xpoint,ypoint,radius,radius);
}
public void paint(Graphics g){
g.fillOval(xpoint,ypoint,radius,radius);
}
}
Code:
int x_final;
int y_final;
public Rect(int x_final, int y_final){
this.x_final=x_final;
this.y_final=y_final;
}
public void paint(Graphics g){
g.setColor(Color.black);
g.drawRect(0,0,x_final,y_final);
}
}
Code: