我试图下一盘棋,但当我试图通过jlabel图标插入棋子时,它们会覆盖实际的棋盘,因此只有棋子留在屏幕上。我怎样才能使这些标签不掩盖它背后的画呢?我是用一个扩展japplet的类来实现的。
更新:它通过使用applet而不是japplet工作,尽管我仍然不知道为什么。
代码如下:
ChessBoard board; // done in another class file
public static int CEL_WIDTH = 65;
public static int MARGIN_X = 50, MARGIN_Y = 50;
imagePos = "../src/Schack/Bilder/";
JLabel label;
public void init() {
setLayout(null);
this.setSize(600, 600);
board = new ChessBoard(MARGIN_X, MARGIN_Y, CEL_WIDTH);
ImageIcon imageIcon = new ImageIcon(getImage(getDocumentBase(), imagePos + "blackRook.png")); //scaling my image
Image image = imageIcon.getImage();
Image newimg = image.getScaledInstance(CEL_WIDTH, CEL_WIDTH, java.awt.Image.SCALE_SMOOTH);
imageIcon = new ImageIcon(newimg);
label = new JLabel(imageIcon);
label.setBounds(MARGIN_X, MARGIN_Y, CEL_WIDTH, CEL_WIDTH);
add(label);
}
@Override
public void paint(Graphics g) {
board.paintChessBoard(g); // another paint method in a different class file
super.paint(g);
}
暂无答案!
目前还没有任何答案,快来回答吧!