Github Link to full download
https://github.com/Jamiex304/Chess-Game
I am currently developing a chess game and have ran into a problem
Currently when a pawn reaches the end of the other side of the board it changes into a white queen by default
I want to let the user decide what it changes into (hence the rules of chess) i was toying around with JOption pane but I am having trouble getting it to work i can run it with our errors but it does nothing for me in terms of chaging the pieces i am looking for some help with the implementation,
The queen code snipet (didnt include full code here because it would be to long all files found on github link if you wish to run the file for yourselfs)
if(!validMove){
int location=0;
if(startY ==0){
location = startX;
}
else{
location = (startY*8)+startX;
}
String pieceLocation = pieceName+".png";
pieces = new JLabel( new ImageIcon(pieceLocation) );
panels = (JPanel)chessBoard.getComponent(location);
panels.add(pieces);
}
else{
if(success){
int location = 56 + (e.getX()/75);
if (c instanceof JLabel){
Container parent = c.getParent();
parent.remove(0);
pieces = new JLabel( new ImageIcon("WhiteQueen.png") );
parent = (JPanel)chessBoard.getComponent(location);
parent.add(pieces);
}
else{
Container parent = (Container)c;
pieces = new JLabel( new ImageIcon("WhiteQueen.png") );
parent = (JPanel)chessBoard.getComponent(location);
parent.add(pieces);
}
}
else{
if (c instanceof JLabel){
Container parent = c.getParent();
parent.remove(0);
parent.add( chessPiece );
}
else {
Container parent = (Container)c;
parent.add( chessPiece );
}
chessPiece.setVisible(true);
}
}
If you want to see what I mean by all means download and run the java file itself you can see the way it only changes to the white queen