GUI를 클릭하면 자바로 체커를 만들고 "새 게임"버튼이 사라집니다. 마우스를 가져 가면 다시 나타나지만 GUI를 클릭하면 다시 사라집니다. 내가 뭘 잘못했는지 잘못 알고 있니?GUI를 클릭하면 JButton이 사라집니다.
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);
}
버튼 작성 방법, 패널/버튼/버튼 등의 클릭 이벤트와 같이 코드의 관련 부분 만 게시하는 것이 도움이 될 수 있습니다. – gwin003
제 1의 나쁜 접근'pnl.setLayout (null);''paint'를 호출 한 후에'validate'를 호출하려고 시도하고'paintComponent'를 오버 라이하는 컨테이너에 페인트하지 말고 종종 윈도우에서 페인트하지 말것 – nachokk
' 그래픽스 그래픽 = jFrame.getGraphics();'! 이것은 스윙에서 사용자 정의 그림이 수행되는 방식이 아닙니다. 당신이 – MadProgrammer