Hi this is my first post in a forum, sorry if I don't have enough information. I'm currently programming a chess engine and have a JFrame displaying the chess board. The board is displayed just fine as well as all the pieces. I'm having a problem when I bring up another JFrame. I do this when a pawn makes it all the way across the board, I want a new JFrame to pop up and give the user the option to choose a new piece(queen, rook, bishop, or horse) to replace their pawn. On the new JFrame, the user will see four images of the pieces, once a piece is clicked the JFrame will close and the game will resume.
Right now the new JFrame appears, but the BufferedImages I call to be drawn on it are displayed in the original JFrame. I am not sure how to specify which JFrame for the Graphics object to write to. I know how to load/display BufferedImages just fine, except I can't seem to select the right JFrame to draw to.
The code below draws a line of text and a horse piece on top of my chess board and not the new JFrame I created. It is executed when a pawn enters the back row of the board.
JFrame piece_select = new JFrame();
piece_select.setVisible(true);
piece_select.setSize(300, 300);
JPanel pieces = new JPanel();
pieces.setVisible(true);
piece_select.add(pieces);
pieces.setBackground(Color.GRAY);
g.drawString("Pick a piece below to replace your pawn.", 20, 20); //Drawn on the board, not piece_select.
g.drawImage(horse, 0, 0, null); //Same thing for this line of code.
The size of the new JFrame is correct as well as the background color I set, however the BufferedImage(horse) is drawn on the original frame and the string. I realize that the Graphics object is in no way associated with the JFrame and JPanel with this code, I just can't figure out how to make it so it is. Any ideas?
Thank you,
Nick