为什么红线部分会有空指针异常???
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class DouDongText extends Applet implements Runnable
{
Image image;
Graphics graphics,imagegraphics ;
String message;
private int pointX,pointY;
Color textcolor,bgcolor;
FontMetrics fontmetrics;
Dimension dimension;
Thread thread ;
public void init()
{
graphics = this.getGraphics();
dimension= this.getSize();
image = this.createImage(dimension.width,dimension.height);
imagegraphics = image.getGraphics();
fontmetrics = graphics.getFontMetrics();
message = "抖动一下啦";
pointX = (dimension.width - fontmetrics.stringWidth(message))/2;
pointY = dimension.height - 10;
String param;
if((param = getParameter("TEXTCOLOR")) == null)
textcolor = Color.blue;
else
textcolor = new Color(Integer.parseInt(param));
if((param = getParameter("BACKGROUNDCOLOR")) == null)
bgcolor = Color.pink;
else
bgcolor = new Color(Integer.parseInt(param));
thread = new Thread(this);
}
public void start()
{
if(thread == null)
thread = new Thread(this);
thread.start();
}
public void run()
{
while(thread != null)
{
try
{
thread.sleep(2000);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
repaint();
}
System.exit(0); //退出程序
}
public void paint(Graphics g)
{
g.setColor(bgcolor);
g.fillRect(0,0,dimension.width,dimension.height);
g.setColor(textcolor);
g.drawString(message,pointX,pointY);
}
public void update(Graphics g)
{
//待续
}
}
帮下忙喽!