Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 两个跑马灯的程序,有点问题,请看下。
zhanghaidang





发贴: 2
积分: 0
于 2006-03-16 23:32 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我写了二个跑马灯的程序,代码如下
第一个:

import java.awt.event.*;
import javax.swing.*;

public class PmdLabel extends JApplet implements Runnable
{
String strLabel, strPmd, strPmdTemp;
Thread T;
public void init()
{
strLabel = new String("☆欢迎光临当当的小站☆");
strPmdTemp = "";
T = new Thread(this);
T.start();
}

public void run()
{

while(true)
{
strPmd = "";
for(int i = 0; i < strLabel.length(); i++)
{
this.showStatus(strPmd);
strPmd += strLabel.charAt(i);
try
{
T.sleep(500);
}
catch(Exception e)
{
e.printStackTrace();
}
}

for(int i = 0; i < strPmd.length(); i++)
{
strPmdTemp = strPmd.substring(i, strPmd.length());
this.showStatus(strPmdTemp);
try
{
T.sleep(500);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
}

第二个:

import javax.swing.*;
import java.awt.*;

public class FontTest extends JApplet implements Runnable
{
String str, strTemp1, strTemp2;
JLabel lblstr;
Font f;
Thread T;
public void init()
{
this.getContentPane().setLayout(new FlowLayout());
str = "锄禾日当午";
lblstr = new JLabel();
this.getContentPane().add(lblstr);
f = new Font("楷体_GB2312", Font.PLAIN, 36);
T = new Thread(this);
T.start();
}

public void run()
{
while(true)
{
strTemp1 = "";
for(int i = 0; i < str.length(); i++)
{
if(i == 0)
strTemp1 = "";
else
{
for(int j = 0; j < str.length()-(str.length()-i); j++)
{
strTemp1 += " ";
}
}
try
{
T.sleep(1000);
}
catch(Exception e)
{
e.printStackTrace();
}
strTemp2 =strTemp1 + str.charAt(i);
lblstr.setFont(f);
lblstr.setText(strTemp2);
lblstr.validate();
}
}
}
}

请大家先运行代码
我感觉第二个有些问题,总觉得空格没有控制好,请大家帮忙改正一下代码,谢谢!我建了一个群,希望大家加入,一起学习进步,群号:6584902


why edited on 2006-03-17 03:25


话题树型展开
人气 标题 作者 字数 发贴时间
4790 两个跑马灯的程序,有点问题,请看下。 zhanghaidang 1965 2006-03-16 23:32

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923