2012-09-07 4 views
0

J'essaye de programmer une machine à sous. Donc, j'ai fait un JPanel, dans lequel je substitue la méthode paintComponent().Dessiner sur une image en constante évolution

public void paintComponent(Graphics g) 
{ 
    Graphics2D g2 = (Graphics2D)g; 

    g2.drawImage(backImage, 0, 0, this.getWidth(), this.getHeight(),null); // Background 
    if(slot1On) //Slot Machine 
    { 
     g2.drawImage(getSlot1(masterCount), 26, 50,slotSizeW,slotSizeH, null); 
    } 
    else 
    { 
     g2.drawImage(getSlot1(slot1Pos), 26, 50,slotSizeW,slotSizeH, null); 
    } 
    g2.setColor(Color.WHITE); // Text 
    g2.setFont(new Font(lblAction.getFont().getName(),Font.BOLD,16)); 
    g2.drawString("Press Space to stop the wheel!", 32, 25); 
    int i,j; 
    for(i=0;i<3;i++) // Lines on the slot machine 
    { 
     g2.setColor(new Color(0,0,0,0.9f)); 
     g2.fillRect(27+ 12 * i + slotSizeW * i, 50 + slotSizeH/2-1, slotSizeW, 3); 
     g2.fillRect(28+ 12 * i + slotSizeW * i, 50 +slotSizeH/2-4, 3,9); 
     g2.fillRect(22+ 12 * i + slotSizeW * (i +1) , 50 +slotSizeH/2-4, 3, 9); 
     for(j=0;j<8;j++) 
     { 
      if(j < 4) 
      { 
       g2.setColor(new Color(0,0,0,0.9f - j * 0.1f)); 
       g2.fillRect(26 + 12 * i + slotSizeW * i, 50 + j * 4, slotSizeW, 4); 
      } 
      else 
      { 
       g2.setColor(new Color(0,0,0,0.9f - (8 - j) * 0.1f)); 
       g2.fillRect(26+ 12 * i + slotSizeW * i, 50 + slotSizeH - (8 - j) * 4, slotSizeW, 4); 
      } 
     } 
    } 
} 

Cependant, tout ce que j'essaie de dessiner après la machine à sous est pas affichée tant la roue de fente se déplacent, comme le montre l'image:

enter image description here

Alors, pourquoi aren » t ils affichent correctement?

Répondre

1

Essayez ceci:

public void paintComponent(Graphics g) 
{ 
super.paintComponent(g); 
//the rest of your painting here 
} 
+0

L'appel super ne marche pas résoudre mon problème. – Daemoth

+0

@Daemoth peut-être fournir un [SSCCE] (http://sscce.org) aiderait à mieux aider plus tôt –

+1

Huh ... j'ai été en mesure de le réparer. Sans raison apparente, faire un .getSubImage() à partir de mon image de slot était à l'origine de mes problèmes, même si la sous-image n'était même pas utilisée ... Eh bien, merci pour votre temps. – Daemoth

Questions connexes