毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 论文 >> 正文

连连看java程序 第6页

更新时间:2008-11-30:  来源:毕业论文

javaj连连看源代码
package kyodai;

import javax.sound.midi.*;
import java.io.*;
import java.net.*;

/**
 * 控制背景音乐
 */
public class Music implements MetaEventListener, Runnable {
 private String midiFile = "sound/bg.mid";
 private Sequence sequence = null;
 private Sequencer sequencer;
 private boolean isPlaying = false;
 private volatile Thread thread;

 public Music() {
  try {
   loadMidi(midiFile);
  }
  catch (InvalidMidiDataException ex) {
  }
  catch (IOException ex) {
  }
 }

 /**
  * 读取midi文件
 */
 public void loadMidi(String filename)
  throws IOException,InvalidMidiDataException {

  URLClassLoader urlLoader = (URLClassLoader)this.getClass().getClassLoader();
  URL url = urlLoader.findResource(filename);
  sequence = MidiSystem.getSequence(url);
 }

 public void play() {
  if (isPlaying) { //如果已经在播放,返回
   return;
  }

  try {
   sequencer = MidiSystem.getSequencer();
   sequencer.open();
   sequencer.setSequence(sequence);

   sequencer.addMetaEventListener(this);
  }
  catch (InvalidMidiDataException ex) {
  }
  catch (MidiUnavailableException e) {
  }

  thread = new Thread(this);
  thread.start();
 }

 public void stop() {
  if (isPlaying) {
   sequencer.stop();
   isPlaying = false;
  }
  if (thread != null) {
   thread = null;
  }
 }

 public void run() {
  Thread currentThread = Thread.currentThread();
  while (currentThread == thread && !isPlaying) {
   sequencer.start();
   isPlaying = true;
   try {
    thread.sleep(1000l);
   }
   catch (InterruptedException ex) {
   }
  }
 }

 public void meta(MetaMessage event) {
  if (event.getType() == 47) {
   System.out.println("Sequencer is done playing.");
  } }
}

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 下一页

连连看java程序 第6页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©751com.cn 辣文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。