欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java swing仿酷狗音樂播放器

 更新時(shí)間:2017年06月05日 11:04:50   作者:明禮馨德  
這篇文章主要為大家詳細(xì)介紹了Java swing實(shí)現(xiàn)音樂播放器,Java開發(fā)圖形界面程序音樂播放器仿酷狗音樂播放器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

今天給大家介紹下用Java swing開發(fā)一款音樂播放器,高仿酷狗音樂播放器,完整源碼地址在最下方,本文只列出部分源碼,因?yàn)樵创a很多,全部貼不下,下面還是老規(guī)矩。來看看運(yùn)行結(jié)果: 

下面我們來看看代碼: 

首先看一下主窗口的實(shí)現(xiàn)代碼: 

package com.baiting;

import java.awt.Dimension;
import java.awt.Toolkit;

import com.baiting.menu.CloseWindow;

/**
 * 窗口
 * @author lmq
 *
 */
public abstract class MusicWindow extends Music {
 
 protected MusicFrame musicFrame;
 
 private String title;
 private int locationX;
 private int locationY;
 
 public MusicWindow() {
 title = getConfigMap().get("title").toString();
 defaultLocation();
 }
 
 public MusicWindow(String title,int width,int height) {
 this.title = title;
 setWidth(width);
 setHeight(height);
 defaultLocation();
 }
 
 public MusicWindow(String title,int width,int height,int locationX,int locationY) {
 this.title = title;
 setWidth(width);
 setHeight(height);
 this.locationX = locationX;
 this.locationY = locationY;
 }
 
 private void defaultLocation() {
 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 locationX = (screenSize.width-getWidth())/2;
 locationY = (screenSize.height-getHeight())/2;
 }
 
 protected MusicFrame createWindow() {
 musicFrame = new MusicFrame();
 musicFrame.setTitle(title);
 musicFrame.setSize(getWidth(), getHeight());
 //musicFrame.setLocation(locationX, locationY);
 musicFrame.setLocationRelativeTo(null);
 musicFrame.addWindowListener(new CloseWindow());
 musicFrame.setMinimumSize(new Dimension(600, 450));
 musicFrame.setVisible(true);
 return musicFrame;
 }

 public String getTitle() {
 return title;
 }

 public void setTitle(String title) {
 this.title = title;
 }

 public int getLocationX() {
 return locationX;
 }

 public void setLocationX(int locationX) {
 this.locationX = locationX;
 }

 public int getLocationY() {
 return locationY;
 }

 public void setLocationY(int locationY) {
 this.locationY = locationY;
 }
 
 

 
}

 看看在線下載歌曲的代碼:

package com.baiting.service;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.baiting.bean.DownFailSong;
import com.baiting.bean.DownedSong;
import com.baiting.http.DownloadSong;
import com.baiting.util.StringUtil;

public class DownloadSongService extends MusicService {

 private static DownloadSongService instance;
 private static Thread downloadThread;
 
 private DownloadSongService() {
 
 }
 
 public static DownloadSongService getInstance() {
 if(null == instance) {
  instance = new DownloadSongService();
 }
 return instance;
 }
 
 public void startDownload() {
 if(null == downloadThread) {
  downloadThread = new Thread(new DownloadSong());
  downloadThread.start();
 } else {
  if(!downloadThread.isAlive()) {
  downloadThread.interrupt();
  downloadThread = null;
  downloadThread = new Thread(new DownloadSong());
  downloadThread.start();
  }
 }
 }
 
 
 public List<DownedSong> getDownedSongAll() {
 File downedListFile = new File(getBasePath()+DOWNLOAD_PATH+"downed.list");
 if(!downedListFile.exists()) {
  try {
  log.info("downed.list文件不存在,正在創(chuàng)建....");
  downedListFile.createNewFile();
  log.info("downed.list文件創(chuàng)建[成功]....");
  } catch (IOException e) {
  log.info("downed.list文件創(chuàng)建[失敗--異常]....");
  e.printStackTrace();
  downedListFile = null;
  return null;
  }
 }
 try {
  BufferedReader reader = new BufferedReader(new FileReader(downedListFile));
   String line = reader.readLine();
   List<DownedSong> list = new ArrayList<DownedSong>();
   int count = 0;
   if(!StringUtil.isEmpty(line)) {
    while(line != null) {
    count++;
    String content = line.replace("\n", "").trim();
   String[] cols = content.split(SEPARATOR);
   if(cols.length>5) {
   DownedSong downedSong = new DownedSong();
   downedSong.setNo(count);
   downedSong.setFileName(cols[0].trim());
   downedSong.setSongName(cols[1].trim());
   downedSong.setSinger(cols[2].trim());
   downedSong.setFileSize(Double.parseDouble(cols[3].trim()));
   downedSong.setPath(cols[4].trim());
   downedSong.setCreateTime(cols[5].trim());
   list.add(downedSong);
   downedSong = null;
   }
   line = reader.readLine();
    }
   }
   reader.close();
   reader = null;
   if(list.size()>0) {
    return list;
   }
   return null;
 } catch (FileNotFoundException e) {
  log.info("文件不存在...");
  e.printStackTrace();
  return null;
 } catch (IOException e) {
  e.printStackTrace();
  return null;
 } finally {
  downedListFile = null;
 }
 }
 
 
 /**
 * 掃描目錄---未完成
 * @return
 */
 public List<DownedSong> getDownedSongByDir() {
 String downedSongDir = getDownloadSongPath();
 File downedDir = new File(downedSongDir);
 if(downedDir.exists() && downedDir.isDirectory()) {
  String[] fileList = downedDir.list();
  for (int i = 0; i < fileList.length; i++) {
  
  }
 }
 return null;
 }
 
 
 /**
 * 判斷歌曲是否存在(通過歌曲名和歌手)
 * @param songName
 * @param singer
 * @return
 */
 public boolean existSongByInfo(String songName,String singer) {
 List<DownedSong> list = getDownedSongAll();
 if(null == list || list.size()<1) {
  return false;
 } 
 boolean flag = false;
 for(DownedSong downedSong : list) {
  if(downedSong.getSongName().equals(songName) && downedSong.getSinger().equals(singer)) {
  flag = true;
  break;
  }
 }
 list = null;
 return flag;
 }
 
 /**
 * 已下載列表中加入新數(shù)據(jù)
 * @param downedSong
 * @return
 */
 public int addDownedSong(DownedSong downedSong) {
 File downedListFile = new File(getBasePath()+DOWNLOAD_PATH+"downed.list");
 if(!downedListFile.exists()) {
  try {
  log.info("downed.list文件不存在,正在創(chuàng)建....");
  downedListFile.createNewFile();
  log.info("downed.list文件創(chuàng)建[成功]....");
  } catch (IOException e) {
  log.info("downed.list文件創(chuàng)建[失敗--異常]....");
  e.printStackTrace();
  downedListFile = null;
  return -1;
  }
 }
 if(null != downedSong) {
  String contents = downedSong.getFileName()+SEPARATOR+
  downedSong.getSongName()+SEPARATOR+downedSong.getSinger()+SEPARATOR+
  downedSong.getFileSize()+SEPARATOR+downedSong.getPath()+SEPARATOR+
  downedSong.getCreateTime()+"\n";
  try {
  BufferedWriter writer = new BufferedWriter(new FileWriter(downedListFile,true));
  writer.write(contents);
  writer.flush();
  writer.close();
  writer = null;
  List<DownedSong> lists = getDownedSongAll();
  int count = lists.size();
  lists = null;
  return count;
  } catch (IOException e) {
  log.info(downedListFile.getName()+"文件信息寫入[失敗---異常]");
  e.printStackTrace();
  return -1;
  } finally {
  downedListFile = null;
  downedSong = null; 
  }
 }
 return -1;
 }
 
 
 
 
 /**
 * 獲取所有下載失敗的歌曲
 * @return
 */
 public List<DownFailSong> getDownFailSongAll() {
 File downedListFile = new File(getBasePath()+DOWNLOAD_PATH+"downFail.list");
 if(!downedListFile.exists()) {
  try {
  log.info("downFail.list文件不存在,正在創(chuàng)建....");
  downedListFile.createNewFile();
  log.info("downFail.list文件創(chuàng)建[成功]....");
  } catch (IOException e) {
  log.info("downFail.list文件創(chuàng)建[失敗--異常]....");
  e.printStackTrace();
  downedListFile = null;
  return null;
  }
 }
 try {
  BufferedReader reader = new BufferedReader(new FileReader(downedListFile));
   String line = reader.readLine();
   List<DownFailSong> list = new ArrayList<DownFailSong>();
   int count = 0;
   if(!StringUtil.isEmpty(line)) {
    while(line != null) {
    count++;
    String content = line.replace("\n", "").trim();
   String[] cols = content.split(SEPARATOR);
   if(cols.length>3) {
   DownFailSong failSong = new DownFailSong();
   failSong.setNo(count);
   failSong.setSongName(cols[0].trim());
   failSong.setSinger(cols[1].trim());
   failSong.setFormat(cols[2].trim());
   failSong.setFailTime(cols[3].trim());
   list.add(failSong);
   }
   line = reader.readLine();
    }
   }
   reader.close();
   reader = null;
   if(list.size()>0) {
    return list;
   }
   return null;
 } catch (FileNotFoundException e) {
  log.info("文件不存在...");
  e.printStackTrace();
  return null;
 } catch (IOException e) {
  e.printStackTrace();
  return null;
 } catch (Exception e) {
  e.printStackTrace();
  return null;
 } finally {
  downedListFile = null;
 }
 }
 
 
 /**
 * 已下載列表中加入新數(shù)據(jù)
 * @param downedSong
 * @return
 */
 public int addDownFailSong(DownFailSong downFailSong) {
 File downFailListFile = new File(getBasePath()+DOWNLOAD_PATH+"downFail.list");
 if(!downFailListFile.exists()) {
  try {
  log.info("downFail.list文件不存在,正在創(chuàng)建....");
  downFailListFile.createNewFile();
  log.info("downFail.list文件創(chuàng)建[成功]....");
  } catch (IOException e) {
  log.info("downFail.list文件創(chuàng)建[失敗--異常]....");
  e.printStackTrace();
  downFailSong = null;
  return -1;
  }
 }
 if(null != downFailSong) {
  String contents = downFailSong.getSongName()+SEPARATOR+downFailSong.getSinger()+SEPARATOR+
  downFailSong.getFormat()+SEPARATOR+downFailSong.getFailTime()+"\n";
  try {
  BufferedWriter writer = new BufferedWriter(new FileWriter(downFailListFile,true));
  writer.write(contents);
  writer.flush();
  writer.close();
  List<DownFailSong> lists = getDownFailSongAll();
  return lists.size();
  } catch (IOException e) {
  log.info(downFailListFile.getName()+"文件信息寫入[失敗---異常]");
  e.printStackTrace();
  return -1;
  } catch (Exception e) {
  e.printStackTrace();
  return -1;
  } finally {
  downFailSong = null;
  contents = null;
  }
 }
 return -1;
 }
 
 
 /**
 * 刪除下載失敗的歌曲列表
 * @param no
 * @return
 */
 public boolean delDownFailSong(int no) {
 List<DownFailSong> lists = getDownFailSongAll();
 if(null != lists && lists.size()>0 && lists.size()>=no && no>0) {
  DownFailSong downFailSong = lists.get(no-1);
  log.info("刪除下載失敗的歌曲《"+downFailSong.getSongName()+"》");
  lists.remove(downFailSong);
  
  StringBuffer strBuff = new StringBuffer();
  if(null != lists && lists.size()>0) {
  for(DownFailSong fs : lists) {
   String contents = fs.getSongName()+SEPARATOR+fs.getSinger()+SEPARATOR+
   fs.getFormat()+SEPARATOR+fs.getFailTime()+"\n";
   strBuff.append(contents);
  }
  } else {
  strBuff.append("");
  }
  File downFailListFile = new File(getBasePath()+DOWNLOAD_PATH+"downFail.list");
  if(!downFailListFile.exists()) {
  try {
   log.info("downFail.list文件不存在,正在創(chuàng)建....");
   downFailListFile.createNewFile();
   log.info("downFail.list文件創(chuàng)建[成功]....");
  } catch (IOException e) {
   log.info("downFail.list文件創(chuàng)建[失敗--異常]....");
   e.printStackTrace();
   return false;
  } finally {
   lists = null;
  }
  }
  try {
  BufferedWriter writer = new BufferedWriter(new FileWriter(downFailListFile,false));
  writer.write(strBuff.toString());
  writer.flush();
  writer.close();
  log.info("刪除下載失敗的歌曲《"+downFailSong.getSongName()+"》--成功---");
  return true;
  } catch (IOException e) {
  log.info(downFailListFile.getName()+"文件信息寫入[失敗---異常]");
  e.printStackTrace();
  return false;
  } finally {
  lists = null;
  downFailListFile = null;
  downFailSong = null;
  }
 }
 return false;
 }
} 

代碼就貼這么多。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Spring核心容器之BeanDefinition解析

    Spring核心容器之BeanDefinition解析

    這篇文章主要介紹了Spring核心容器之BeanDefinition解析,Spring 將管理的對象稱之為 Bean,容器會先實(shí)例化 Bean,然后自動注入,實(shí)例化的過程就需要依賴 BeanDefinition,需要的朋友可以參考下
    2023-11-11
  • Spring Cloud Config 使用本地配置文件方式

    Spring Cloud Config 使用本地配置文件方式

    這篇文章主要介紹了Spring Cloud Config 使用本地配置文件方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • 淺談Java自定義注解相關(guān)知識

    淺談Java自定義注解相關(guān)知識

    今天帶大家來學(xué)習(xí)Java注解的相關(guān)知識,文中對自定義注解作了非常詳細(xì)的介紹,對正在學(xué)習(xí)Java的小伙伴們很有幫助,需要的朋友可以參考下
    2021-05-05
  • JavaWeb實(shí)體類轉(zhuǎn)為json對象的實(shí)現(xiàn)方法

    JavaWeb實(shí)體類轉(zhuǎn)為json對象的實(shí)現(xiàn)方法

    這篇文章主要介紹了JavaWeb實(shí)體類轉(zhuǎn)為json對象的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Spring如何按業(yè)務(wù)模塊輸出日志到不同的文件詳解

    Spring如何按業(yè)務(wù)模塊輸出日志到不同的文件詳解

    最近做項(xiàng)目時(shí)有一個記錄操作日志的需求,比如某個用戶進(jìn)行了查詢、刪除、修改等操作,下面這篇文章主要給大家介紹了關(guān)于Spring如何按業(yè)務(wù)模塊輸出日志到不同文件的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • java編程實(shí)現(xiàn)求質(zhì)數(shù)與因式分解代碼分享

    java編程實(shí)現(xiàn)求質(zhì)數(shù)與因式分解代碼分享

    這篇文章主要介紹了Java編程實(shí)現(xiàn)求質(zhì)數(shù)與因式分解代碼分享,對二者的概念作了簡單介紹(多此一舉,哈哈),都是小學(xué)數(shù)學(xué)老師的任務(wù),然后分享了求解質(zhì)數(shù)和因式分解的Java代碼,具有一定借鑒價(jià)值,需要的朋友可以參考下。
    2017-12-12
  • SpringBoot通過整合Dubbo解決@Reference注解問題

    SpringBoot通過整合Dubbo解決@Reference注解問題

    這篇文章主要介紹了SpringBoot通過整合Dubbo解決@Reference注解問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-03-03
  • SpringMVC攔截器快速掌握上篇

    SpringMVC攔截器快速掌握上篇

    攔截器(Interceptor)是一種動態(tài)攔截方法調(diào)用的機(jī)制,在SpringMVC中動態(tài)攔截控制器方法的執(zhí)行。本文將詳細(xì)講講SpringMVC中攔截器的概念及入門案例,感興趣的可以嘗試一下
    2022-08-08
  • SpringBoot?HikariCP配置項(xiàng)及源碼解析

    SpringBoot?HikariCP配置項(xiàng)及源碼解析

    這篇文章主要為大家介紹了SpringBoot?HikariCP配置項(xiàng)及源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02
  • 詳解如何在Java中加密和解密zip文件

    詳解如何在Java中加密和解密zip文件

    在本文中,我們來學(xué)習(xí)如何用Zip4j庫創(chuàng)建受密碼保護(hù)的壓縮文件并將其解壓,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以參考一下
    2022-09-09

最新評論