没有合适的资源?快使用搜索试试~ 我知道了~
Java Swing制作多行滚动歌词显示控件.doc
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 175 浏览量
2022-06-09
12:20:16
上传
评论
收藏 168KB DOC 举报
温馨提示
试读
16页
Java Swing制作多行滚动歌词显示控件
资源推荐
资源详情
资源评论
Java Swing
制作多行滚动歌词显示控件
首先上图一张,为最终制作的效果图,不喜欢或感到失望的朋友可以先行离开
大家已经看到效果图了。那么下面就介绍设计思路和源代码
首先要想显示歌词,就要对歌词文件进行抽象。下面这个类是对某一行歌词文件进行了抽
象。
[java]view plain copy
1. /*
2. *Tochangethistemplate,chooseTools|Templates
3. *andopenthetemplateintheeditor.
4. */
5. packagemusicbox.model.lyric;
6.
7. /**
8. *
9. *@authorRandyzhao
10. */
11. publicclassLyricStatement{
12.
13. privatelongtime=0;//时间,单位为 10ms
14. privateStringlyric="";//歌词NN
15.
16. /*
17. *获取时间N
18. */
19. publiclonggetTime(){
20. returntime;
21. }
22. /*
23. *设置时间N
24. *time:被设置成的时间N
25. */
26.
27. publicvoidsetTime(inttime){
28. this.time=time;
29. }
30. /*
31. *设置时间N
32. *time:被设置成的时间字符串,格式为 mm:ss.ms
33. */
34.
35. publicvoidsetTime(Stringtime){
36. Stringstr[]=time.split(":|\\.");
37. this.time=Integer.parseInt(str[0])*6000+Integer.parseInt(str
[1])*100+
38. Integer.parseInt(str[2]);
39. }
40. /*
41. *获取歌词N
42. */
43.
44. publicStringgetLyric(){
45. returnlyric;
46. }
47. /*
48. *设置歌词N
49. */
50.
51. publicvoidsetLyric(Stringlyric){
52. this.lyric=lyric;
53. }
54. /*
55. *打印歌词N
56. */
57.
58. publicvoidprintLyric(){
59. System.out.println(time+":"+lyric);
60. }
61. }
特别注意成员变量 time 表示该行歌词显示的时间,单位是N10ms这是为了和歌词文件中时
间的单位统一。
某一行歌词可以用一个 LyricStatement 类的实例来表示。那么一个歌词文件就可以解析为
一个 List<LyricStatement>。为了方便测试,以下附上本人自己写的一个歌词文件解释器。
[java]view plain copy
1. /*
2. *Tochangethistemplate,chooseTools|Templates
3. *andopenthetemplateintheeditor.
4. */
5. packagemusicbox.model.lyric;
6.
7. importjava.io.BufferedReader;
8. importjava.io.FileInputStream;
9. importjava.io.IOException;
10. importjava.io.InputStreamReader;
11. importjava.net.URLDecoder;
12. importjava.util.ArrayList;
13. importjava.util.List;
14. importjava.util.regex.Matcher;
15. importjava.util.regex.Pattern;
16.
17. /**
18. *
19. *@authorRandyzhao
20. */
21. publicclassLyricReader{
22.
23. BufferedReaderbufferReader=null;//读取
文件实例NN
24. publicStringtitle="";//歌曲
题目NN
25. publicStringartist="";//演唱
者NN
26. publicStringalbum="";//专辑NN
27. publicStringlrcMaker="";//歌词
制作者NN
28. List<LyricStatement>statements=newArrayList<LyricStatement>();
//歌词NN
29. /*
30. *实例化一个歌词数据.歌词数据信息由指定的文件提供.
31. *fileName:指定的歌词文件.
32. */
33.
34. publicLyricReader(StringfileName)throwsIOException{
35. //incasethespaceinthefileNameisreplacedbythe%20
36. FileInputStreamfile=newFileInputStream(URLDecoder.decode(fileN
ame,"UTF-8"));
37. bufferReader=newBufferedReader(newInputStreamReader(file,"GB2
312"));
38.
39. //将文件数据读入内存NN
40. readData();
41. }
42.
43. publicList<LyricStatement>getStatements(){
44. returnstatements;
45. }
46.
47. /*
48. *读取文件中数据至内存.
49. */
50. privatevoidreadData()throwsIOException{
51. statements.clear();
52. StringstrLine;
53. //循环读入所有行NN
54. while(null!=(strLine=bufferReader.readLine())){
55. //判断该行是否为空行NN
56. if("".equals(strLine.trim())){
57. continue;
58. }
59. //判断该行数据是否表示歌名NN
60. if(null==title||"".equals(title.trim())){
61. Patternpattern=Pattern.compile("\\[ti:(.+?)\\]");
62. Matchermatcher=pattern.matcher(strLine);
63. if(matcher.find()){
64. title=matcher.group(1);
65. continue;
66. }
剩余15页未读,继续阅读
资源评论
oligaga
- 粉丝: 50
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功