求JAVA注释,详细一点,小弟新手 40
publicclassAudio{publicstaticfinalStringuserDir="./midi/";publicAudio(){newThread(new...
public class Audio {
public static final String userDir = "./midi/";
public Audio(){
new Thread(new BackMusic()).start() ;
}
/**
* 认输
*/
public void giveUp(){
AudioStream giveUpAudioStream = null ;
FileInputStream gameWinFis = null ;
FileInputStream giveUpFis = null ;
try {
giveUpFis = new FileInputStream(userDir + "gameover.wav") ;
gameWinFis = new FileInputStream(userDir + "gamewin.wav") ;
giveUpAudioStream = new AudioStream(giveUpFis) ;
AudioPlayer.player.start(giveUpAudioStream);
Thread.sleep(2000) ;
// 大家拍手
giveUpAudioStream = new AudioStream(gameWinFis) ;
AudioPlayer.player.start(giveUpAudioStream);
giveUpAudioStream.close() ;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally{
try {
if(giveUpAudioStream != null){
giveUpAudioStream.close() ;
giveUpAudioStream = null ;
}
if(giveUpFis != null){
giveUpFis.close() ;
giveUpFis = null ;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 背景音乐
*/
public void playBackSound(){
AudioStream checkAudioStream = null ;
FileInputStream backFis = null ;
try {
backFis = new FileInputStream(userDir + "back.mid") ;
checkAudioStream = new AudioStream(backFis) ;
AudioPlayer.player.start(checkAudioStream);
Thread.sleep(114000) ;
checkAudioStream.close() ;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally{
try {
if(checkAudioStream != null){
checkAudioStream.close() ;
checkAudioStream = null ;
}
if(backFis != null){
backFis.close() ;
backFis = null ;
}
} catch (IOException e) {
e.printStackTrace();
}
}
playBackSound() ;
}
/**
* 将军
*/
public void playCheckSound(){
try {
FileInputStream checkFis = new FileInputStream(userDir + "check.wav") ;
AudioStream checkAudioStream = new AudioStream(checkFis) ;
AudioPlayer.player.start(checkAudioStream);
Thread.sleep(10) ;
checkAudioStream.close() ;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void playGoSound(){
try {
FileInputStream goFis = new FileInputStream(userDir + "go.wav") ;
AudioStream goAudioStream = new AudioStream(goFis) ;
AudioPlayer.player.start(goAudioStream);
Thread.sleep(10) ;
goAudioStream.close() ;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private class BackMusic implements Runnable{
public void run() {
playBackSound() ;
}
} 展开
public static final String userDir = "./midi/";
public Audio(){
new Thread(new BackMusic()).start() ;
}
/**
* 认输
*/
public void giveUp(){
AudioStream giveUpAudioStream = null ;
FileInputStream gameWinFis = null ;
FileInputStream giveUpFis = null ;
try {
giveUpFis = new FileInputStream(userDir + "gameover.wav") ;
gameWinFis = new FileInputStream(userDir + "gamewin.wav") ;
giveUpAudioStream = new AudioStream(giveUpFis) ;
AudioPlayer.player.start(giveUpAudioStream);
Thread.sleep(2000) ;
// 大家拍手
giveUpAudioStream = new AudioStream(gameWinFis) ;
AudioPlayer.player.start(giveUpAudioStream);
giveUpAudioStream.close() ;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally{
try {
if(giveUpAudioStream != null){
giveUpAudioStream.close() ;
giveUpAudioStream = null ;
}
if(giveUpFis != null){
giveUpFis.close() ;
giveUpFis = null ;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 背景音乐
*/
public void playBackSound(){
AudioStream checkAudioStream = null ;
FileInputStream backFis = null ;
try {
backFis = new FileInputStream(userDir + "back.mid") ;
checkAudioStream = new AudioStream(backFis) ;
AudioPlayer.player.start(checkAudioStream);
Thread.sleep(114000) ;
checkAudioStream.close() ;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally{
try {
if(checkAudioStream != null){
checkAudioStream.close() ;
checkAudioStream = null ;
}
if(backFis != null){
backFis.close() ;
backFis = null ;
}
} catch (IOException e) {
e.printStackTrace();
}
}
playBackSound() ;
}
/**
* 将军
*/
public void playCheckSound(){
try {
FileInputStream checkFis = new FileInputStream(userDir + "check.wav") ;
AudioStream checkAudioStream = new AudioStream(checkFis) ;
AudioPlayer.player.start(checkAudioStream);
Thread.sleep(10) ;
checkAudioStream.close() ;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void playGoSound(){
try {
FileInputStream goFis = new FileInputStream(userDir + "go.wav") ;
AudioStream goAudioStream = new AudioStream(goFis) ;
AudioPlayer.player.start(goAudioStream);
Thread.sleep(10) ;
goAudioStream.close() ;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private class BackMusic implements Runnable{
public void run() {
playBackSound() ;
}
} 展开
展开全部
public void playGoSound(){
//文件流的操作如果文件或路径不存在,则执行异常处理
try {
// 文件路径
FileInputStream goFis = new FileInputStream(userDir + "go.wav") ;
//音频流定义
AudioStream goAudioStream = new AudioStream(goFis) ;
//调用AudioPlayer,开始播放文件
AudioPlayer.player.start(goAudioStream);
//播放完成后,线程暂停10ms
Thread.sleep(10) ;
//关闭音频流
goAudioStream.close() ;
}
//文件不存在似的处理
catch (FileNotFoundException e) {
//打印错误信息
e.printStackTrace();
}
//输入输出异常处理
catch (IOException e) {
e.printStackTrace();
}
//这是线程休眠时,打断线程执行的异常处理
catch (InterruptedException e) {
e.printStackTrace();
}
}
private class BackMusic implements Runnable{
public void run() {
playBackSound() ;
}
}
//文件流的操作如果文件或路径不存在,则执行异常处理
try {
// 文件路径
FileInputStream goFis = new FileInputStream(userDir + "go.wav") ;
//音频流定义
AudioStream goAudioStream = new AudioStream(goFis) ;
//调用AudioPlayer,开始播放文件
AudioPlayer.player.start(goAudioStream);
//播放完成后,线程暂停10ms
Thread.sleep(10) ;
//关闭音频流
goAudioStream.close() ;
}
//文件不存在似的处理
catch (FileNotFoundException e) {
//打印错误信息
e.printStackTrace();
}
//输入输出异常处理
catch (IOException e) {
e.printStackTrace();
}
//这是线程休眠时,打断线程执行的异常处理
catch (InterruptedException e) {
e.printStackTrace();
}
}
private class BackMusic implements Runnable{
public void run() {
playBackSound() ;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询