I am trying to build an application that finds all possible ways of arranging 8 queens on a chess board in such a way that no two of them are on either the same row, column, or diagonal. I am also trying to do this applying what I think is supposed to be MVC architecture. However, I am a little confused and am having hard time with my view component.
here I have my view component:
import javax.swing.*;
import java.awt.*;
public class Eksi extends JPanel{
//this field variable holds 64 squares of a chess board
//that is, 64 instances of my Kutia class
private Kutia[][] k;
private Model doc;
public Eksi(){
RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);
JFrame x = new JFrame();
x.getContentPane().add(this);
x.setSize(500, 500);
x.setVisible(true);
}
public void paintComponent(Graphics g){
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
if((i+j)%2 == 0){
g.setColor(Color.black);
}
else{
g.setColor(Color.red);
}
g.fillRect(50 + i*20, 50 + j*20, 20, 20);
}
}
if(k != null){
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
if(k[j][i].occupied()){
g.setColor(Color.white);
g.drawString(k[i][j].figura(), i*20 + 52, j*20 + 70);
try { Thread.sleep(3000); }
catch (InterruptedException e) { }
}
}
}
try { Thread.sleep(300); }
catch (InterruptedException e) { }
}
}
public void ndihmesePaint(Kutia[][] ituk){
k = ituk;
for(int i = 0; i < k.length; i++){
for(int j = 0; j < k.length; j++){
System.out.print(k[i][j].figura() + " " );
}
System.out.println();
}
repaint();
}
}
I expect that every time I call method ndihmesePaint() in my controller class, as long as I update the parameter I pass on to the method, the view should repaint() and show me a different result. However, calling this method causes no effect on my view. what am I missing? anyone?
I think posting my other two classes is unnecessary. if need be, I will post the two classes also.