歌词滚动代码java,音乐歌词滚动
如何在java程序中加上滚动条,为什么我的程序滚动条没显示?
请使用JScroolPane。比如要为一个多行文本域加上滚动条,要使用如下代码:
创新互联公司服务项目包括曲靖网站建设、曲靖网站制作、曲靖网页制作以及曲靖网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,曲靖网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到曲靖省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
jf.add(new JScrollPane(new TextArea(50,30))));
其中jf代表窗口。
java解析lrc文件代码
lrc可以通过如下util工具类进行转换,如果想知道结果是否读取的有问题,可以直接用记事本打开lrc文件的,之后和输出结果比对一下就行。
package com.routon.utils;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.util.Log;
/**
* parse lrc file tool
* eg:
* utilLrc lrc = new utilLrc("/sdcard/test.lrc");
* get song name : String title = lrc.getTitle();
* get performer name : String artist = lrc.getArtist();
* get album name: String album = lrc.getAlbum();
* get lrcmaker name: String lrcMaker = lrc.getLrcMaker();
* get song list: ListStatement list = lrc.getLrcList();
*
* @author xuweilin
*
*/
public class utilLrc {
private static String TAG = "utilLrc";
public class Statement {
private double time = 0.0; //time, 0.01s
private String lyric = ""; //song word
/*
* get time
*/
public double getTime() {
return time;
}
/*
* set time
*/
public void setTime(double time) {
this.time = time;
}
/*
* set time.format:mm:ss.ms
*/
public void setTime(String time) {
String str[] = time.split(":|\\.");
this.time = Integer.parseInt(str[0])*60+Integer.parseInt(str[1])+Integer.parseInt(str[2])*0.01;
}
/*
* get lrc word
*/
public String getLyric() {
return lyric;
}
/*
* set lrc word
*/
public void setLyric(String lyric) {
this.lyric = lyric;
}
}
private BufferedReader bufferReader = null;
private String title = "";
private String artist = "";
private String album = "";
private String lrcMaker = "";
private ListStatement statements = new ArrayListStatement();
/*
*
* fileName
*/
public utilLrc(String fileName) throws IOException{
FileInputStream file = new FileInputStream(fileName);
bufferReader = new BufferedReader(new InputStreamReader(file, "utf-8"));
readData();
}
/*
* read the file
*/
private void readData() throws IOException{
statements.clear();
String strLine;
while(null != (strLine = bufferReader.readLine()))
{
if("".equals(strLine.trim()))
{
continue;
}
if(null == title || "".equals(title.trim()))
{
Pattern pattern = Pattern.compile("\\[ti:(.+?)\\]");
Matcher matcher = pattern.matcher(strLine);
if(matcher.find())
{
title=matcher.group(1);
continue;
}
}
if(null == artist || "".equals(artist.trim()))
{
Pattern pattern = Pattern.compile("\\[ar:(.+?)\\]");
Matcher matcher = pattern.matcher(strLine);
if(matcher.find())
{
artist=matcher.group(1);
continue;
}
}
if(null == album || "".equals(album.trim()))
{
Pattern pattern = Pattern.compile("\\[al:(.+?)\\]");
Matcher matcher = pattern.matcher(strLine);
if(matcher.find())
{
album=matcher.group(1);
continue;
}
}
if(null == lrcMaker || "".equals(lrcMaker.trim()))
{
Pattern pattern = Pattern.compile("\\[by:(.+?)\\]");
Matcher matcher = pattern.matcher(strLine);
if(matcher.find())
{
lrcMaker=matcher.group(1);
continue;
}
}
int timeNum=0;
String str[] = strLine.split("\\]");
for(int i=0; istr.length; ++i)
{
String str2[] = str[i].split("\\[");
str[i] = str2[str2.length-1];
if(isTime(str[i])){
++timeNum;
}
}
for(int i=0; itimeNum;++i)
{
Statement sm = new Statement();
sm.setTime(str[i]);
if(timeNumstr.length)
{
sm.setLyric(str[str.length-1]);
}
statements.add(sm);
}
}
sortLyric();
}
/*
* judge the string is or not date format.
*/
private boolean isTime(String string)
{
String str[] = string.split(":|\\.");
if(3!=str.length)
{
return false;
}
try{
for(int i=0;istr.length;++i)
{
Integer.parseInt(str[i]);
}
}
catch(NumberFormatException e)
{
Log.e(TAG, "isTime exception:"+e.getMessage());
return false;
}
return true;
}
/*
* sort the word by time.
*/
private void sortLyric()
{
for(int i=0;istatements.size()-1;++i)
{
int index=i;
double delta=Double.MAX_VALUE;
boolean moveFlag = false;
for(int j=i+1;jstatements.size();++j)
{
double sub;
if(0=(sub=statements.get(i).getTime()-statements.get(j).getTime()))
{
continue;
}
moveFlag=true;
if(subdelta)
{
delta=sub;
index=j+1;
}
}
if(moveFlag)
{
statements.add(index, statements.get(i));
statements.remove(i);
--i;
}
}
}
/**
* get title
* @return
*/
public String getTitle(){
return title;
}
/**
* get artist
* @return
*/
public String getArtist(){
return artist;
}
/**
* get album
* @return
*/
public String getAlbum(){
return album;
}
/**
* get lrc maker
* @return
*/
public String getLrcMaker(){
return lrcMaker;
}
/**
* get song list
* @return
*/
public ListStatement getLrcList(){
return statements;
}
}
如何在java中实现 歌词同步显示
如果你打开歌词文件查看的话,前面都会有时间.我想歌词同步也是靠的这个时间吧
求教,急用!JAVA按歌词文件的时间标签从小到大排列内容,然后最好能给我做个方法,让我直接调用,排
你好,这是你要的方法,直接输入路径调用就可以了,输出结果是sorted-加原文件名
/**
* 根据路径和编码 重新排列歌词中的文件,转换后的文件是“sorted-原文件”
*
* @param source 原文件
*/
public static void sortLyric(String source) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(source), "UTF-8"));
ListString lines = new ArrayListString();
String line;
while ((line = br.readLine()) != null) {
lines.add(line);
}
br.close();
Collections.sort(lines);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("sorted-" + source, false), "UTF-8"));
for (String everyLine : lines) {
bw.write(everyLine);
bw.newLine();
bw.flush();
}
bw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
java实现文字循环上下滚动并逐渐放大或缩小
是用java Applet 么?
我试着写了个,估计代码不是很简, 你看看是不是这种效果:坐标自己可以去调整下,名字从上到下移动,从上到中间的时候变大,过了中间逐渐变小,过了底部显示下一个名字,循环显示,题意应该没理解错吧
import java.applet.*;
import java.awt.*;
public class ShowName extends Applet
{
String names[]=new String[]{"luojian","qianhongcheng","fenglingxin","luoxiaojian","wangyin"};
int size=20;
int index =0;
int offsetY=20;
int size1 =size;
int size2 =size-10;
int size3 =size-20;
int name1Y =0+offsetY;
int name2Y =-40+offsetY;
int name3Y =-80+offsetY;
int name1Index =index;
int name2Index =index+1;
int name3Index =index+2;
public void init()
{
resize(400,400);
setVisible(true);
}
public void paint(Graphics g)
{
try
{
checkName("name1Index",name1Y);
checkName("name2Index",name2Y);
checkName("name3Index",name3Y);
String name1 =names[name1Index];
String name2 =names[name2Index];
String name3 =names[name3Index];
name1Y=checkY(name1Y);
name2Y=checkY(name2Y);
name3Y=checkY(name3Y);
size1=checkSize(name1Y,size1);
size2=checkSize(name2Y,size2);
size3=checkSize(name3Y,size3);
Font font1 = new Font(null,Font.PLAIN,size1);
Font font2 = new Font(null,Font.PLAIN,size2);
Font font3 = new Font(null,Font.PLAIN,size3);
g.setFont(font1);
g.drawString(name1, 100, name1Y);
g.setFont(font2);
g.drawString(name2, 100, name2Y);
g.setFont(font3);
g.drawString(name3, 100, name3Y);
Thread.sleep(300);
}
catch(Exception e)
{
e.printStackTrace();
}
repaint();
}
public int checkSize(int p,int psize)
{
if(p200)
psize =psize+10;
if(p200)
psize =psize-10;
if(p=400)
psize =size-20;
return psize;
}
public int checkY(int p)
{
if(p=400)
p=-80;
else
p=p+40;
return p;
}
public void checkName(String nameindex,int p)
{
if(p=400)
{
if(nameindex.equals("name1Index"))
{
if(name1Index4)
name1Index++;
else
name1Index =index;
}
if(nameindex.equals("name2Index"))
{
if(name2Index4)
name2Index++;
else
name2Index =index;
}
if(nameindex.equals("name3Index"))
{
if(name3Index4)
name3Index++;
else
name3Index =index;
}
}
}
}
滚动的小球 java源代码
;
要制造那种效果只需要大约 30 行 Java 代码:
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
class RollingBall extends JPanel {
Ellipse2D.Float ball = new Ellipse2D.Float( -100, 100, 50, 50 );
public void paintComponent( Graphics g ) {
super.paintComponent( g );
Graphics2D g2 = ( Graphics2D ) g;
// Draw the ball
g2.fill( ball );
// Draw the rotating ellipse by skewing the Device Space
double angdeg = // One rotation per ball's travelling over its perimeter
ball.x++ % ( Math.PI * ball.width ) / ( Math.PI * ball.width ) * 360;
g2.rotate( Math.toRadians( angdeg ), ball.getCenterX( ), ball.getCenterY( ) );
g2.scale( .5, 1 );
g2.translate( ball.getCenterX( ), 0 );
g2.setColor( Color.gray );
g2.fill( ball );
}
public void roll( ) throws Exception {
while( true ) {
repaint( );
Thread.sleep( 8 );
}
}
public static void main( String[ ] args ) throws Exception {
JFrame f = new JFrame( );
RollingBall rb = new RollingBall( );
f.setSize( 999, 185 );
f.getContentPane( ).add( rb );
f.setVisible( true );
rb.roll( );
}
}
网站名称:歌词滚动代码java,音乐歌词滚动
文章链接:http://azwzsj.com/article/hesgpp.html