Hi!
Why does the following code work :
Code:
public class Game extends Applet
{
public void init() {}
public void paint(Graphics g)
{
Image img = getImage(getCodeBase(), "Ball.png");
BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(img, 50, 50, this);
g.drawImage(bi, 0, 0, this);
}
}
But not this:
Code:
public class Game extends Applet
{
private BufferedImage bi = null;
public void init()
{
Image img = getImage(getCodeBase(), "Ball.png");
bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(img, 50, 50, this);
}
public void paint(Graphics g)
{
g.drawImage(bi, 0, 0, this);
}
}