Below is paint component, and called methods, but on my screen nothing appears.. my Panel is just blank. Ideas on what i may be missing? I know for a fact that the code IS iterating through paintComponent
public void paintComponent (Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
b.draw(g2d);
pieces.draw(g2d);
//redraw elements here.
}
//code for the b.draw()
public void draw(Graphics2D g){
for (int i = 0;i<8;i++){
for(int j = 0; j < 8; j++){
if (i%2 == 0){
if(j%2 ==0){
g.setColor(Color.BLACK);
g.drawRect(i*cw, j*ch, w, h);
}else{
g.setColor(Color.YELLOW);
g.drawRect(i*cw, j*ch, w, h);
}
}else{
if(j%2 ==0){
g.setColor(Color.YELLOW);
g.drawRect(i*cw, j*ch, w, h);
}else{
g.setColor(Color.BLACK);
g.drawRect(i*cw, j*ch, w, h);
}
}
}
}
}
//code for pieces.draw()
public void draw(Graphics2D g){
//g.setColor(color);
//g.draw(piece);
for(int i = 0; i< 8;i++){
for(int j = 0; j < 8; j++){
if(c[i][j] == 'B'){
g.setColor(Color.BLUE);
}else if (c[i][j] == 'W'){
g.setColor(Color.WHITE);
}else{//empty
continue;
}
g.drawOval(b.getBlockWidth()*i+b.getBlockWidth()/2, j*b.getBlockHeight()+b.getBlockHeight()/2, b.getBlockWidth()/2, b.getBlockHeight()/2);
}
}
}

New Topic/Question
Reply


MultiQuote


|