简单字符跑马灯

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;            
            }
        }
    }
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值