Graphics.fillOval

Mr.Java

Mitglied
Frage: Wie bekomme ich es hin dass folgender Quelcode so funktioniert wie er laufen sollte:

Java:
public class MPanel extends JPanel{
		
			public void paintComponent(Graphics g){
				
				super.paintComponent(g);
				
				g.setColor(Color.BLUE);
				g.fillOval((int) (Position_x1), (int)(500), (int) (Radius1), (int) (Radius1));
				
				g.setColor(Color.GREEN);
				g.fillOval((int) (Position_x2), (int)(500), (int)  (Radius2), (int) (Radius2));
				
			}
			}

Anmerkung:
Position_x1 = Mittelpunkt1...
Der Mitelpunkt der Y Achse soll immer 500 sein. Im Moment sind die Kreise nie da wo sie seien sollten und der Radius stimmt auch noch nicht
 
Zuletzt bearbeitet:
Hallo dein Problem ist das du dir nicht die Dokumentation durchliest!

Hier die Beschreibung des Konstruktors:

public FillOval(int x, int y, int width,int height)

Parameters:
x - left edge of the rectangle
y - top edge of the rectange
width - width of the rectangle
height - height of the rectange

Also musst du es wie folgt abändern:

Java:
public class MPanel extends JPanel{
 
			public void paintComponent(Graphics g){
 
				super.paintComponent(g);
 
				g.setColor(Color.BLUE);
				g.fillOval((int) (Position_x1-Radius1), (int)(500-Radius1), (int) (Radius1*2.0), (int) (Radius1*2.0));
 
				g.setColor(Color.GREEN);
				g.fillOval((int) (Position_x2-Radius2), (int)(500-Radius2), (int)  (Radius2*2.0), (int) (Radius2*2.0));
 
			}
			}

P.S. In Java werden Variablen klein geschrieben mit CamelCase: also positionX2, radius2...

Gruß,
AntiMuffin
 

Zurück
Oben