0
我在繪製一些圖像時遇到了一些問題。 我正在使用JDialog來顯示背景和分離的類來顯示卡(使用精靈)。背景上的油漆部件
背景顯示不錯,但JPanel不顯示。
這裏是我的代碼:
public Main(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
//Call the board to draw cards
Board plateau = new Board();
this.add(plateau);
}
/**
* Paint the background
*
* @param g
*/
@Override
public void paint(Graphics g) {
try {
Graphics2D g2 = (Graphics2D) g;
this.background_image = ImageIO.read(new File(this.background));
Graphics2D big = this.background_image.createGraphics();
Rectangle rectangle = new Rectangle(0, 0, 20, 20);
g2.setPaint(new TexturePaint(this.background_image, rectangle));
Rectangle rect = new Rectangle(0, 0, this.getWidth(), this.getHeight());
g2.fill(rect);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
和應吸取的卡類:
@Override
public void paint(Graphics g) {
try {
this.image = ImageIO.read(new File("Ressources/images/cardsprite.gif"));
//4 lines
for (int i = 0; i < 4; i++) {
//13 rows
for (int j = 0; j < 13; j++) {
//Split one card
BufferedImage temp = this.image.getSubimage(j * this.CARD_WIDTH,
i * this.CARD_HEIGHT, this.CARD_WIDTH, this.CARD_HEIGHT);
g.drawImage(temp, j * this.CARD_WIDTH,
i * this.CARD_HEIGHT, this);
}
}
} catch (IOException ex) {
Logger.getLogger(Board.class.getName()).log(Level.SEVERE, null, ex);
}
如果我把卡拉絲級到主的paint方法,它工作正常。
我錯過了什麼嗎?
謝謝