使用双缓冲区在applet上绘图会有空指针异常?
package usedoublebuffering;
// 程序:使用双缓冲区
// 范例文件:UseDoubleBuffering.java
import java.awt.*;
import java.applet.*;
public class UseDoubleBuffering extends Applet implements Runnable
{
int X,Y,moveX,moveY,width,height;
Thread newThread;
Image OffScreen;
Graphics drawOffScreen;
public void init()
{
X = 0;
Y = 0;
moveX = 2;
moveY = 3;
//Dimension d=getSize();
//d.width=400;d.height=300;
//setSize(d);
width = getSize().width;
height = getSize().height;
OffScreen = createImage(width,height); //此处会出现空指针异常
drawOffScreen = OffScreen.getGraphics();
}
public void start()
{
newThread = new Thread(this);
newThread.start();
}
public void stop()
{