下面是一个Applet程序,其功能是显示有闪烁特效的从左向右的滚动文字。要求定义6种颜色:RED,GREEN,ORANGE, GRAY,YELLOW,BLUE,让文字在滚动过程中根据文字的位置循环选定—种颜色,并快速切换,达到一边移动一边闪烁的效果,同时要求通过htm1文件传递所显示的文字和延迟时间的参数,Applet程序能够根据参数实现显示功能。请改正程序中的错误(有下划线的语句),使程序能输山正确的结果。
注意:不改动程序的结构,不得增行或删行。
程序运行结果如下:
import java.applet.Applet;
import java.awt.*;
/*
<applet code="ex12_3.class" width=800 height=400 >
<param name=text value="Welcome to NCR Examination!">
<param name=delay value="50">
</applet>
*/
public class ex12_3 extends Applet implements Runnable
private String strText;
private Thread thMover = null;
private int nX, nY, nDelay;
private Font fFont ;
private int getParameter(String s1, int s2)
String s = getParameter(s1) ;
return (s != null) Integer•parseInt(s) : s2 ;
private String getParameter(String s1, String s2)
String s = getParameter(s1) ;
return (s != null) Integer.parseInt(s) : s2 ;
public void init()
fFont = new Font("TimesRome", Font.BOLD, 40) ;
setBackground(Color.black);
strText = getParameter("text","Put your message in strText parm");
nX = getSize().height;
nY = 80 ;
nDelay = getParameter("delay", 80) ;
public void start()
if(thMover == null)
thMover = new Thread(this);
thMover.start();
public void stop()
thMover = null;
public void run()
while(thMover != null)
try
Thread.sleep(nDelay);
catch(InterruptedException e)
repaint ( );
public void paint(Graphics g)
switch(nX % 6)
case 0: g.setColor(Color. RED);
break;
case 1: g.setColor(Color. GREEN)
break;
case 2: g.setColor(Color. ORANGE;
break;
case 3: g.setColor(Color.GRAY);
break;
case 4: g.setColor(Color.YELLOW ;
break;
case 5: g.setColor(Color. BLUE);
g.setFont(fFont);
g.drawString(strText, nX, nY);
if(nX <= 0)
nX= getSize ( ) .width ;
ex12 3.htm1
<HTML>
<HEAD>
<TITLE>ex12_3</TITLE>
</HEAD>
<BODY>
<applet code="exl2_3.class" width=800 height=400 >
<param name=text value="Welcome to NCR Examination!">
<param name=delay value="50">
</applet>
</BODY>
</HTML>