Hi,
ich programmiere derzeit 4 gewinnt und habe nun für jede Spalte ein JPanel. Darin möchte ich jetzt bis zu 10 Kreise zeichnen. 1 Kreis klappt schon aber bei wiederholtem zeichnen wird der erste überschrieben. Wie kann ich mehrere Kreise speichern? bis jetzt:
Das ist eines der bis zu 10Jpanels (JPanel-Array)
[HIGHLIGHT="Java"]class Spalten_Panels extends JPanel
{
int s;
int spalten;
int zeilen;
int y;
//Graphics2D g2d;
Graphics gp;
int width = 0;
int height = 0;
Graphics2D g2d[];
int contentS = 0;
public Spalten_Panels(int s, int spalten, int zeilen, Spielfeld sf)
{
g2d = new Graphics2D[zeilen];
this.y = 0;
this.s = s;
this.spalten = spalten;
this.zeilen = zeilen;
this.setBounds(s*62+10, 75, 60, 60*zeilen+zeilen*2);
this.setBackground(SystemColor.controlShadow);
this.setVisible(true);
sf.add(this);
}
//Das hier ist die Hauptmethode. Repaint führt immer das aus, was hier drin behandelt wird, weswegen man mit den anderen Methoden nur die
//Variablen bei fillOval(....) ändern kann.
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
g2d[contentS] = (Graphics2D) g;
g2d[contentS].fillOval(0, y, width, height);
}
public void draw(int y, int contentS)
{
this.contentS = contentS;
System.out.println(contentS);
width = 60;
height = 60;
this.y = y;
}
public void move(int i)
{
y += i;
}
public int getRecentY()
{
return y;
}
}[/HIGHLIGHT]
Gruß Alex
ich programmiere derzeit 4 gewinnt und habe nun für jede Spalte ein JPanel. Darin möchte ich jetzt bis zu 10 Kreise zeichnen. 1 Kreis klappt schon aber bei wiederholtem zeichnen wird der erste überschrieben. Wie kann ich mehrere Kreise speichern? bis jetzt:
Das ist eines der bis zu 10Jpanels (JPanel-Array)
[HIGHLIGHT="Java"]class Spalten_Panels extends JPanel
{
int s;
int spalten;
int zeilen;
int y;
//Graphics2D g2d;
Graphics gp;
int width = 0;
int height = 0;
Graphics2D g2d[];
int contentS = 0;
public Spalten_Panels(int s, int spalten, int zeilen, Spielfeld sf)
{
g2d = new Graphics2D[zeilen];
this.y = 0;
this.s = s;
this.spalten = spalten;
this.zeilen = zeilen;
this.setBounds(s*62+10, 75, 60, 60*zeilen+zeilen*2);
this.setBackground(SystemColor.controlShadow);
this.setVisible(true);
sf.add(this);
}
//Das hier ist die Hauptmethode. Repaint führt immer das aus, was hier drin behandelt wird, weswegen man mit den anderen Methoden nur die
//Variablen bei fillOval(....) ändern kann.
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
g2d[contentS] = (Graphics2D) g;
g2d[contentS].fillOval(0, y, width, height);
}
public void draw(int y, int contentS)
{
this.contentS = contentS;
System.out.println(contentS);
width = 60;
height = 60;
this.y = y;
}
public void move(int i)
{
y += i;
}
public int getRecentY()
{
return y;
}
}[/HIGHLIGHT]
Gruß Alex
Zuletzt bearbeitet von einem Moderator: