我正在尝试书中的一些applet例子" JAVA:HERBERT SCHILDT"的完整参考。我遇到了这个applet示例,它是在applet窗口中从右向左滚动文本,并且由于某种原因它没有获取参数值。我哪里错了?提前谢谢。
以下是代码:
package applet1;
import java.awt.*;
import java.applet.*;
/*
<applet code="ParamBanner" width=300 height=80>
<param name=message value="Valar Morghulis">
</applet>
*/
public class ParamBanner extends Applet implements Runnable
{
String msg;
Thread t;
boolean stopFlag;
@Override
public void init()
{
setBackground(Color.black);
setForeground(Color.white);
}
@Override
public void start()
{
msg = getParameter("message");
if(msg == null)
msg = "Not Found";
msg = "" + msg;
t = new Thread(this);
stopFlag = false;
t.start();
}
@Override
public void run()
{
char ch;
for(;;)
{
try
{
repaint();
Thread.sleep(250);
ch = msg.charAt(0);
msg = msg.substring(1,msg.length());
msg += ch;
if(stopFlag)
break;
}
catch(InterruptedException e)
{}
}
}
@Override
public void stop()
{
t = null;
stopFlag = true;
}
@Override
public void paint(Graphics g)
{
g.drawString(msg,10,30);
}
}