Repainting at a specific rectangle on an image
Has anyone tried using the method repaint(int, int, width, height) method to only paint at the specific place? I tried doing that but the image smudge when i moved my player. I have to minimize it and maximize it back for it to show a clean image at an updated position.
Can anyone help me with some hints?
[319 byte] By [
Hanz_05a] at [2007-11-27 10:51:09]

> The question to me is: do you mix Swing and AWT components?
Yes, if you're doing that, stop!
I am not sure if am doing the right thing......
public void paint(Graphics g)
{
//codes
}
Then i just called the repaint method somewhere in my code
repaint(int , int, width, height);
> Either one if can work...So whats the different
> between Swing and AWT? Does the swing uses
> paintComponent() rather than paint()?
Swing double-buffers by default which may fix your repainting woes.
I also think it is better supported and optimized in the later versions,
while AWT...?
Method paint still exists, after all, JComponent is in the Component hierarchy.
However, in JComponent, paint calls paintComponent, paintBorder and paintChildren.
Typically, if you want a custom component you extend JPanel (not Canvas)
and override paintComponent, not paint:
protected void paintComponent(Graphics g) {
super.paintComponent(g);
//do you rendering here
}
> Ok... I will try that.. thanks.. is the
> super.paintComponent(g) necessary?
You could comment it out and see what happens :-)
In JPanel, it will fill the component's bounds with the background color.