Problem with double buffering - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Problem with double buffering

DysartDysart Posts: 35Member
[b][red]This message was edited by Dysart at 2005-10-25 18:59:33[/red][/b][hr]
Here's the deal I'm implementing a card game for a project.
Now I'm having a problem on drawing the cards image on the component(I'm using swing), they apear to slow on the component.
How do I make the cards apear more faster.

Here's the sourcecode for the paintComponent method:
[code]
public void paintComponent(Graphics g) {
super.paintComponent(g);

Toolkit kit = Toolkit.getDefaultToolkit();
Image im = kit.getImage("King.gif");
g.drawImage(im,0,0,this);




}
public void paintChildren(Graphics g) {
super.paintChildren(g);
Toolkit kit = Toolkit.getDefaultToolkit();

if( !acert ){
interFace.draw(g,kit,this);

}

}
[/code]

And the method that draws the cards in Class Interface
[code]
public void draw(Graphics g,Toolkit kit,MyPanel mypanel)
{


for (int i = 0; i < 13; i++){
Image im = kit.getImage((String)images.get(i));
g.drawImage(im,20*i+100,500,mypanel);
mypanel.repaint();//this should speed up the process :S
}


}

[/code]


I know that in theory I should put all the card images on the memory and then draw them into the screen, but since java is object oriented there must be a simpler way, I think :S.

Thanks in advance.


Sign In or Register to comment.