2014-09-13 7 views
0

자바로 처음으로 애플릿을 만들고, 두 개의 튜토리얼을 읽고 이중 버퍼링을위한 다양한 솔루션을 찾았습니다. 나는 그들 사이의 차이점, 장단점 등이 무엇인지 알고 싶습니다. 미리 감사드립니다! 먼저 하나이중 버퍼링 방법의 차이점

: 하나

public void update(Graphics g) { 
    if (offImage == null) { 
     offImage = createImage(this.getWidth(), this.getHeight()); 
     offGraphics = offImage.getGraphics(); 
    } 
    offGraphics.setColor(getBackground()); 
    offGraphics.fillRect(0, 0, getWidth(), getHeight()); 
    offGraphics.setColor(getForeground()); 
    paint(offGraphics); 
    g.drawImage(offImage, 0, 0, this); 
} 

둘째 :

public void init() { 
    offImage = createImage(getWidth(), getHeight()); 
    offGraphics = offImage.getGraphics(); 
} 

public void paint(Graphics g) { 
    g.drawImage(offImage,0,0,this); 
} 

public void update(Graphics g) { 
    paint(g); 
} 

답변

1

그것은 거의 동일합니다. 그래도 페인트 방법을 사용하면 그래픽 개발에서 주로 사용되기 때문에 처음으로 코드를 확인할 많은 사람들이 그것을 검색 할 것입니다.