文本文件如下:
[00:01.00][迷你歌词官方歌词组]ID:frchu制作
[00:02.00]︿﹀︿﹀︿﹀︿﹀︿﹀︿﹀︿﹀︿
[00:03.00]www.minilyrics.com 迷你歌词
[00:04.00]www.yemusic.com 放肆音乐通
[00:05.00]﹀︿﹀︿﹀︿﹀︿﹀︿﹀︿﹀︿﹀
[00:06.00]港台歌手:周杰伦
[00:07.00]专辑:七里香 歌名:七里香
[00:08.00]作曲:周杰伦 作词:方文山
[00:15.00] 
[00:24.68]3
[00:25.68]2
[00:26.68]1
[00:27.68]窗外的麻雀
[00:30.63]在电线杆上多嘴
[00:34.24]你说这一句
[00:37.29]很有夏天的感觉
程序中,当单击start按钮时,开始按照前面的时间(如:[00:06.00])按行读文件。只要功能相似即可。功能要求像迷你歌词。谢谢!!希望大家帮忙啊!

解决方案 »

  1.   

    // read file into String[] str... SimpleDateFormat f = new SimpleDateFormat("mm:ss.SS");
      try {
        long now = f.parse("00:00.00").getTime();    for (int i = 0; i < strs.length; ++i) {
          String s = strs[i];
          String time = s.substring(1, 9);
          String content = s.substring(10);
          long next = f.parse(time).getTime();
          Thread.sleep(next-now);
          now = next;
          System.out.println(content);
        }
      }
      catch (Exception e) {}
      

  2.   

    呵呵 ,谢谢大家了!!!  在请教helpall(was jl) 一下,怎样实现当前显示行呈现高亮或变颜色啊
    呵呵。马上送分给大家!!!
      

  3.   

    一言难尽, 看看下贴吧.
    不好意思.我从来没有用过QQ, 自然QQ号也是没有的了.http://forum.java.sun.com/thread.jspa?threadID=626698
      

  4.   

    import java.io.*;
    import java.util.*;
    /**
     *这个类中将提供一个从文本中按行读出文本,
     *并保存在数组中的方法。
     */
    class ReadFile
    {
           //集合类
           private Vector str =  new Vector();
           
           //将文本文件中的文本按行存放在集合类中,并返回该集合类       
           public Vector  ReadTextByRow(String fileName)
           {
                try{
         BufferedReader inStream = new BufferedReader(new FileReader(fileName));
        
         String line = inStream.readLine();
         int i=0;
         while(line!=null)
         {
            str.add(line);
            
            line = inStream.readLine();
            i++;
        }
         inStream.close();
         }catch(FileNotFoundException e){
        
         e.printStackTrace();
        }catch(IOException e){
         e.printStackTrace();
        }
        
        return str;
           }
           
           public static void main(String[] args)
           {
               ReadFile  rf = new ReadFile();
               
               Vector strin = rf.ReadTextByRow("test.txt");
                    System.out.println("length:"+strin.size());
               for(int i=0;i<strin.size();i++)
               {
                    System.out.println("Line"+i+":"+(String)strin.elementAt(i));
               }
           }}
      

  5.   

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.font.*;
    import java.awt.color.*;
    import java.text.*;
    import java.util.*;
    /**本类实现文本随时间而动态显示
     *
     */public class TextDisplay extends JFrame implements ActionListener{
    //GUI所需组件
    private JTextField title = new JTextField(20);
    private JLabel prompt = new JLabel("input file field:");
    private JButton read = new JButton("Read start");
    private JPanel command = new JPanel();
        JTextArea content = new JTextArea();

    //构造方法,初始化各组件
    public TextDisplay(){
    super("文本显示");
    read.addActionListener(this);

    command.setLayout(new GridLayout(2,2,1,1) );
    command.add(prompt);
    command.add(title);
    command.add(read);
    content.setLineWrap(true);
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add("North",command);
    this.getContentPane().add("Center",content);
    this.getContentPane().add(new JScrollPane(content));

    content.setEditable(false);
    //content.setBackground();


    }
        public void displayText()
    {
    ReadFile  rf = new ReadFile();
            String tit = title.getText();   
            Vector strin = rf.ReadTextByRow(tit);
            
        SimpleDateFormat f = new SimpleDateFormat("mm:ss.SS");
            try 
            {
                 long now = f.parse("00:00.00").getTime();             for (int i = 0; i < strin.size(); i++) {
                      String s = (String)strin.elementAt(i);
                      String time = s.substring(1, 9);
                      String con = s.substring(10);
                      long next = f.parse(time).getTime();
                      Thread.sleep(next-now);
                      now = next;
                      
                      content.append(con+"\n");
                      //在控制台上显示
                      System.out.println("Line"+i+":"+con);
                      //测试代码,取出TextArea中的内容,在控制台上显示。
                      //在控制台上可以看到content.getText()的内容,
                      //为什么TextArea中没有显示啊??????????
                      //请帮忙啊  前辈  !!!!!!!!!!!
                      System.out.println(content.getText());
                 }
            }
        catch (Exception e) {}
    }
    //单击read start按钮将执行的动作
    public void actionPerformed(ActionEvent evt){
    String fileName = title.getText();
    if(evt.getSource()==read)
    {
        content.setText("");
    displayText();
    }

    }
    //主方法main
    public static void main(String[] args){
    TextDisplay text = new TextDisplay();
    text.setSize(400,300);
    text.setVisible(true);
    }  
    }
      

  6.   

    if(evt.getSource()==read)
                    {
                            content.setText("");
                            new Thread(){public void run() {
                                displayText();
                            }}.start();
                    }