我正在用java制作跳棋,当我点击GUI时“新游戏”按钮消失了。当我将鼠标悬停在它上面时它会重新出现,但如果我单击 GUI,它会再次消失。你知道我做错了什么/做错了吗?
public void setFrame()
{
boardSize = 10;
squareSize = 50;
int imageSize = boardSize * squareSize;
image = new BufferedImage(imageSize, imageSize, BufferedImage.TYPE_INT_ARGB);
imageIcon = new ImageIcon(image);
jLabel = new JLabel(imageIcon);
button = new JButton("New Game");
button.setFocusable(false);
button.setBounds(375, 5, 100, 20);
pnl = new JPanel();
pnl.setBounds(400, 10, 200, 100);
pnl.setLayout(null);
pnl.add(button);
jFrame = new JFrame("Checker Board");
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.add(jLabel, BorderLayout.CENTER);
jFrame.add(pnl);
jFrame.setSize(506, 558);
jFrame.setResizable(false);
jFrame.setLocationRelativeTo(null);
jFrame.setVisible(true);
jFrame.validate();
}
/**
* Paint the checker board onto the Image.
*/
public void paint()
{
Graphics graphics = jFrame.getGraphics();
pnl.paint(graphics);
button.paint(graphics);
graphics.setColor(Color.black);
Font font = new Font("Score", Font.BOLD, 20);
graphics.setFont(font);
graphics.drawString("Score: ", 150, 47);
graphics.drawString("Turn: ", 20, 47);
graphics.setFont(font.deriveFont(0, 16.0F));
graphics.drawString("Red: " + Game.score.getScoreRed() + " Black: " + Game.score.getScoreBlack(), 230, 47);
graphics.drawString((Game.redTurn ? "Red" : "Black"), 80, 47);
// paint a red board
graphics.setColor(Color.red);
graphics.fillRect(xShift, zShift, boardSize * squareSize, boardSize * squareSize);
// paint the black squares
graphics.setColor(Color.black);
for (int row = 0; row < boardSize; row++)
{
for (int col = row % 2; col < boardSize; col += 2)
{
graphics.fillRect( row * squareSize + xShift, col * squareSize + zShift, squareSize, squareSize );
}
}
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
if(Game.board.pieces[i][j] != null)
{
Color pieceColor = Game.board.pieces[i][j].getColor().equals(EnumTeam.BLACK) ? Color.gray : Color.pink;
graphics.setColor(pieceColor);
graphics.fillOval((i * 50) + 10 + xShift, (j * 50) + 10 + zShift, 30, 30);
if(Game.board.pieces[i][j].isKing())
{
pieceColor = Game.board.pieces[i][j].getColor().equals(EnumTeam.BLACK) ? Color.darkGray : Color.magenta;
graphics.setColor(pieceColor);
graphics.fillOval((i * 50) + 20 + xShift, (j * 50) + 20 + zShift, 10, 10);
}
}
}
}
graphics.setColor(Color.cyan);
drawRect(graphics, Game.board.getSelectedX(), Game.board.getSelectedZ(), 5);
}