import static javaconsole.JavaConsole.*;
public class LEDDemo
{
public static void main(String[] args)
{
String msg = "齐齐哈尔大学计控学院软件工程系! ";
int x = 0; //广告首字母x和y坐标
int y = 11;
int xdir = 1; //字符串广告运动方向:1向右运动 -1:向左
int index = 0; //变颜色的字符在字符串中的下标位置
int delaytime = 100; //延迟时间:单位毫秒
int len = msg.length(); //字符串广告的长度
set_size(80,25);
set_title("字符跑马灯!");
hide_cursor();
while(true)
{
//1.绘制广告字符串(蓝色)
gotoxy(x,y);
set_color(0,9);
System.out.print(msg);
//2.绘制变颜色的字符(红色)
gotoxy(x + 2 * index, y); //一个汉字字符在输出占两个字符的宽度
set_color(0,0xc);
System.out.print(msg.charAt(index));
//3.延迟一段时间
delay(delaytime);
//4.清除广告字符串
gotoxy(x,y);
System.out.printf("%" + len * 2 + "s"," ");
//5.根据运动方向修改首字母坐标以及判断边界修改运动方向
x = x + xdir;
if(x <= 0)
{
xdir = 1; //到达最左边,则换方向向右
}
if(x >= (79 - len * 2))
{
xdir = -1; //到达最右边,则换方向向左
}
index++; //变颜色的字符下标加1
if(index > len - 1)
{
index = 0;
}
}
}
}