2012-09-07 5 views
0

슬롯 머신을 프로그래밍하려고합니다. 그래서 JPanel을 만들었습니다. paintComponent() 메서드를 덮어 씁니다.끊임없이 변화하는 그림 위에 그리기

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); 
      } 
     } 
    } 
} 

그러나, 모든 것을 내가 슬롯 머신만큼 이동 슬롯 휠 표시되지 후 그림과 같이 그려보십시오 : 그래서

enter image description here

, 왜 때로 믿을 수 ' 그들은 올바르게 표시되지 않습니까?

답변

1

이 시도 :

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

슈퍼 전화를 내 문제를 해결 나던. – Daemoth

+0

@ Daemoth가 [SSCCE] (http://sscce.org)를 제공해 주면 더 빨리 도움을받을 수 있습니다. –

+1

허 ... 나는 고칠 수있었습니다. 뚜렷한 이유가 없으므로, 내 슬롯 사진에서 .getSubImage()를 수행하면 하위 이미지가 사용되지 않았더라도 문제가 발생했습니다 ... 오. – Daemoth

관련 문제