没有合适的资源?快使用搜索试试~ 我知道了~
JAVA特效实例59动态文字.doc
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 59 浏览量
2022-06-10
07:23:52
上传
评论
收藏 65KB DOC 举报
温馨提示
试读
14页
JAVA特效实例59动态文字
资源推荐
资源详情
资源评论
实例 59 动态文字
本例知识点 一句话讲解
新学
知识
使用 Thread 类 管理线程
使用 StringTokenizer 类 处理文字显示
已学
知识
使用 String 类 处理字符串
使用 Color 类 设置字体颜色
一、练习具体要求
本练习制作动态文字的实例。如图 59-1 所示,程序执行后,创建一个带有动态文字的
面板,文字的字体和字型以及文字的跳跃速度都可以通过程序设置。
二、程序及注释
(1)编程思路:首先,本练习因为要制作动态文字的实例,所以首先要设置要显示的
文字:先通过语句 s = getParameter("text")得到文字,然后通过语句 s.getChars(0 , s.length(),
textChars, 0) 把要 显示 的 字 符 串 保 存 在 字 符 串 数 组 textChars 里 , 最 后 得 到 文 件 中的
AnimText.html 字体参数和字型参数,进行文字的属性设置。然后,因为要实现动态效果 ,
所以要用到线程,首先在函数 public void start()里通过语句 thread = new Thread(this)生成线
程,通过语句 thread.start()启动线程,在 public void run()函数里运行线程,在 public void
stop()撤销线程,这样使线程很好的配合了小程序的运行流程。最后,通过函数 public
boolean mouseDown(java.awt.Event evt, int x, int y) 响应按下鼠标的动作。
(2)程序实现及注释:
//AnimText.java
import java.awt.*;
import java.util.StringTokenizer;
public class AnimText extends java.applet.Applet implements Runnable {
//变量定义
public static final int TYPE_BLINK = 1;
public static final int TYPE_WAVE = 2;
public static final int TYPE_RANDOM = 3;
public static final int ALIGN_LEFT = 1;
public static final int ALIGN_CENTER = 2;
public static final int ALIGN_RIGHT = 3;
char textChars[];
Thread thread;
int type;
int style;
int defaultMin=8;
int defaultMax=28;
int max;
int min;
int defaultStep = 2;
int step;
int align;
String rgbDelimiter = ":,.";
StringTokenizer st;
Color fgColor;
Color bgColor;
boolean threadSuspended = false;
static final String defaultString = "Welcome to Java!";
String fontString;
Font fonts[];
int current[];
int direction[];
//每一个字符的宽度
int charWidth[];
//每一个字符的高度
int charHeight;
boolean resized = false;
boolean readyToPaint = true;
int naptime;
int defaultNaptime = 100;
int Width;
int Height;
int defaultWidth = 300;
int defaultHeight = 100;
int maxWidth = 600;
int maxHeight = 400;
int n;
Image offI;
Graphics offG;
int totalWidth;
int leader = 10;
//初始化小程序
public void init() {
String s;
Integer intObj;
s = getParameter("text");
if (s == null)
s = defaultString;
textChars = new char[s.length()];
s.getChars(0 , s.length(), textChars, 0);
s = getParameter("font");
if (s == null)
fontString = "TimesRoman";
else if (s.equalsIgnoreCase("TimesRoman"))
剩余13页未读,继续阅读
资源评论
oligaga
- 粉丝: 52
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功