最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java音樂播放器編寫源碼

 更新時(shí)間:2017年06月05日 11:31:27   作者:塵封  
這篇文章主要為大家詳細(xì)介紹了java音樂播放器的編寫源碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java音樂播放器的具體代碼,供大家參考,具體內(nèi)容如下

源碼:

package baidu;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.media.bean.playerbean.*; //這個(gè)包要用到JMF

public class MP3 extends JFrame implements Runnable {
public JLabel shijian;

private JSlider sldDiameter;

public MediaPlayer soumd1;

public JButton playSound, loopSound, stopsound;

public JButton tjian, shanc, baocun, duqu;

public JPanel jp1, jp2, jp3, jp4;

public JList jl;

int zongmiao=0;

public Vector vector, mingcheng;

boolean fo = false, geshi = false;

JLabel jl1, jl2, sj1, sj2;

JTextField jt1, jt2;

JButton queding, xiugai;

int zong = 0;

int a = 0, b = 0, you = 1,mm=0;

int fenzhong, miaozhong;

public MP3() {
 super("java簡(jiǎn)單音樂播放器");
 soumd1 = new MediaPlayer();
 Container c = getContentPane();
 c.setLayout(new FlowLayout());
 mingcheng = new Vector();
 jp1 = new JPanel();
 shijian = new JLabel();
 jp1.add(shijian);
 c.add(jp1);
 playSound = new JButton("開始播放");
 loopSound = new JButton("循環(huán)播放");
 stopsound = new JButton("停止播放");
 jp2 = new JPanel();
 jp2.add(playSound);
 jp2.add(loopSound);
 jp2.add(stopsound);
 c.add(jp2);
 jp4 = new JPanel();
 sj1 = new JLabel();
 sj2 = new JLabel();
 sldDiameter = new JSlider(SwingConstants.HORIZONTAL, 0, 100, 0);
 sldDiameter.setMajorTickSpacing(1);
 sldDiameter.setPaintTicks(true);
 jp4.add(sj1);
 jp4.add(sldDiameter);
 jp4.add(sj2);
 c.add(jp4);
 vector = new Vector();
 jl = new JList(mingcheng);
 jl.setVisibleRowCount(5);
 jl.setFixedCellHeight(40);
 jl.setFixedCellWidth(265);
 jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 c.add(new JScrollPane(jl));
 tjian = new JButton("添加");
 shanc = new JButton("刪除");
 duqu = new JButton("讀取");
 baocun = new JButton("保存");
 jp3 = new JPanel();
 jp3.add(tjian);
 jp3.add(shanc);
 jp3.add(baocun);
 jp3.add(duqu);
 c.add(jp3);

 try {
  String s = "c:\music.txt";
  ObjectInputStream input = new ObjectInputStream(
   new FileInputStream(s));
  lujin a1 = (lujin) input.readObject();
  mingcheng = a1.b;
  vector = a1.a;
  jl.setListData(mingcheng);
 } catch (Exception e) {
  System.out.println("c盤沒有保存音樂文件");
  //e.printStackTrace();
 }

 baocun.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent event) {
  JFileChooser fileChooser = new JFileChooser(); // 實(shí)例化文件選擇器
  fileChooser
   .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); // 設(shè)置文件選擇模式,此處為文件和目錄均可
  if (fileChooser.showSaveDialog(MP3.this) == JFileChooser.APPROVE_OPTION) { // 彈出文件選擇器,并判斷是否點(diǎn)擊了打開按鈕
   String fileName = fileChooser.getSelectedFile()
    .getAbsolutePath(); // 得到選擇文件或目錄的絕對(duì)路徑
   mmm(vector, mingcheng, fileName);
  }
  }
 });
 duqu.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent event) {
  JFileChooser fileChooser = new JFileChooser(); // 實(shí)例化文件選擇器
  fileChooser
   .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); // 設(shè)置文件選擇模式,此處為文件和目錄均可
  if (fileChooser.showOpenDialog(MP3.this) == JFileChooser.APPROVE_OPTION) { // 彈出文件選擇器,并判斷是否點(diǎn)擊了打開按鈕
   String fileName = fileChooser.getSelectedFile()
    .getAbsolutePath(); // 得到選擇文件或目錄的絕對(duì)路徑
   try {
   ObjectInputStream input = new ObjectInputStream(
    new FileInputStream(fileName));
   lujin a1 = (lujin) input.readObject();
   mingcheng = a1.b;
   vector = a1.a;
   jl.setListData(mingcheng);
   } catch (Exception e) {
   e.printStackTrace();
   }
  }
  }
 });
 playSound.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
  if (jl.getSelectedIndex() >= 0) {
   String yy = (String) vector.get(jl.getSelectedIndex());
   File ff = new File(yy);
   if (ff.exists()) {
   if (yy.matches("[\S\s]*.mp3")|| yy.matches("[\S\s]*.MP3")) {
    if (soumd1 != null) {
    a = 0;
    b = 0;
    you = 0;
    soumd1.stop();
    }
     soumd1.setMediaLocation("file:/" + yy);
    fo = true;
    soumd1.start();
    geshi=true;
    try {
    Thread.sleep(500);
    } catch (InterruptedException eee) {
    }
    zongmiao=(int)soumd1.getDuration().getSeconds();
    if(zongmiao>10000)
    {
    try {
     Thread.sleep(500);
    } catch (InterruptedException ew) {
    }
    zongmiao=(int)soumd1.getDuration().getSeconds();
    }
    zongmiao=(int)soumd1.getDuration().getSeconds();
    String aa=fen(zongmiao);
     sj2.setText(aa);
   } else
    JOptionPane.showMessageDialog(null,
     "播放文件格式的有錯(cuò),無法播放 建議刪除");
   } else
   JOptionPane.showMessageDialog(null,
    "此歌曲文件已經(jīng)不存在,建議刪除");
  }
  else
   JOptionPane.showMessageDialog(null, "請(qǐng)選擇音樂文件");
  }
 });
 loopSound.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
  if (jl.getSelectedIndex() >= 0) {
   String yy = (String) vector.get(jl.getSelectedIndex());
   File ff = new File(yy);
   if (ff.exists()) {
   if (yy.matches("[\S\s]*.mp3")|| yy.matches("[\S\s]*.MP3")) {
    if (soumd1 != null) {
    a = 0;
    b = 0;
    you = 0;
    soumd1.stop();
    }
     soumd1.setMediaLocation("file:/" + yy);
    fo = true;
    soumd1.start();
    geshi=true;
    try {
    Thread.sleep(500);
    } catch (InterruptedException we) {
    }
    zongmiao=(int)soumd1.getDuration().getSeconds();
    if(zongmiao>10000)
    {
    try {
     Thread.sleep(500);
    } catch (InterruptedException we) {
    }
    zongmiao=(int)soumd1.getDuration().getSeconds();
    }
    zongmiao=(int)soumd1.getDuration().getSeconds();
    String aa=fen(zongmiao);
     sj2.setText(aa);
   } else
    JOptionPane.showMessageDialog(null,
     "播放文件格式的有錯(cuò),無法播放 建議刪除");
   } else
   JOptionPane.showMessageDialog(null,
    "此歌曲文件已經(jīng)不存在,建議刪除");

  }
  else
   JOptionPane.showMessageDialog(null, "請(qǐng)選擇音樂文件");
  }
 });
 stopsound.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
  a = 0;
  b = 0;
  you = 0;
  mm=0;
  geshi=false;
  fo = false;
  sldDiameter.setMaximum(100);
  sldDiameter.setValue(0);
  sj1.setText(null);
  sj2.setText(null);
  if (jl.getSelectedIndex() >= 0)
   soumd1.stop();

  }
 });
 tjian.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent event) {
  JFileChooser fileChooser = new JFileChooser(); // 實(shí)例化文件選擇器
  fileChooser
   .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); // 設(shè)置文件選擇模式,此處為文件和目錄均可
  fileChooser.setCurrentDirectory(new File(".")); // 設(shè)置文件選擇器當(dāng)前目錄
  fileChooser
   .setFileFilter(new javax.swing.filechooser.FileFilter() {
    public boolean accept(File file) { // 可接受的文件類型
    String name = file.getName().toLowerCase();
    return name.endsWith(".mp3")
     || file.isDirectory();
    }
    public String getDescription() { // 文件描述
    return "音樂文件(*.mp3)";
    }
   });
  if (fileChooser.showOpenDialog(MP3.this) == JFileChooser.APPROVE_OPTION) { // 彈出文件選擇器,并判斷是否點(diǎn)擊了打開按鈕
   String fileName = fileChooser.getSelectedFile()
    .getAbsolutePath(); // 得到選擇文件或目錄的絕對(duì)路徑
   vector.add(fileName);
   StringBuffer buffer = daoxu(fileName);
   mingcheng.add(buffer);
  }
  }
 });
 shanc.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent event) {
  if (jl.getSelectedIndex() >= 0) {
   mingcheng.removeElementAt(jl.getSelectedIndex());
   vector.removeElementAt(jl.getSelectedIndex());
   jl.setListData(mingcheng);
  }
  }
 });
 jl.addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent event) {
  if (event.getClickCount() == 2) {
   if (jl.getSelectedIndex() >= 0) {
   String yy = (String) vector.get(jl.getSelectedIndex());
   File ff = new File(yy);
   if (ff.exists()) {
    if (yy.matches("[\S\s]*.mp3")|| yy.matches("[\S\s]*.MP3")) {
    if (soumd1 != null) {
     a = 0;
     b = 0;
     you = 0;
     soumd1.stop();
    }
      soumd1.setMediaLocation("file:/" + yy);
    fo = true;
    soumd1.start();
    geshi=true;
    try {
     Thread.sleep(500);
    } catch (InterruptedException e) {
    }
    zongmiao=(int)soumd1.getDuration().getSeconds();
    if(zongmiao>10000)
    {
     try {
     Thread.sleep(500);
     } catch (InterruptedException e) {
     }
    zongmiao=(int)soumd1.getDuration().getSeconds();
    }
    String aa=fen(zongmiao);
      sj2.setText(aa);
    } else
    JOptionPane.showMessageDialog(null,
     "播放文件格式的有錯(cuò),無法播放 建議刪除");
   } else
    JOptionPane.showMessageDialog(null,
     "此歌曲文件已經(jīng)不存在,建議刪除");

   }
  }
  if (event.isMetaDown()) {
   if (jl.getSelectedIndex() >= 0) {
   int a = jl.getSelectedIndex();
   xiugai x = new xiugai();
   jt1.setText(mingcheng.get(jl.getSelectedIndex()) + "");
   jt2.setText(vector.get(jl.getSelectedIndex()) + "");
   }
  }
  }
 });
 addWindowListener(new WindowAdapter() {
  public void windowClosing(WindowEvent e) {
  String s = "c:\music.txt";
  mmm(vector, mingcheng, s);
  System.exit(0);
   }
 });
 setSize(300, 400);
 setVisible(true);
}

public void run() {
 while (true) {
  Date now = new Date();
  shijian.setText("當(dāng)前時(shí)間: " + now.toString());
  try {
  Thread.sleep(1000);
  } catch (InterruptedException e) {
  }
  if(geshi){
  you=(int)soumd1.getMediaTime().getSeconds();
  mm =you%60;
   if(you!=0)
  if(you%60==0)
  {
   b++;
  }
   sj1.setText(b+":"+mm);
  sldDiameter.setMaximum(zongmiao);
  if(you!=zongmiao)
   sldDiameter.setValue(you);
  else {
   sldDiameter.setValue(0);
  mm=0;
    b=0;
  }
  }
 }
}

public StringBuffer daoxu(String fileName) {
 String mc = "";
 for (int i = fileName.length(); i >= 1; i--) {
  if (fileName.charAt(i - 1) == '\')
  break;
  mc += fileName.charAt(i - 1);
 }
 StringBuffer buffer = new StringBuffer(mc);
 StringBuffer mm = buffer.reverse();
 return mm;
}

public void mmm(Vector vector, Vector mingcheng, String lujin) {
 lujin a = new lujin(vector, mingcheng);
 try {
  ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(lujin));
  output.writeObject(a);
  output.flush();
  output.close();
 } catch (Exception e) {

 }
}
public String fen(int yy) {
  fenzhong = (int) yy / 60;
  miaozhong = (int) yy % 60;
  String sss = fenzhong + ":" + miaozhong;
  return sss;
}

public static void main(String agrs[]) {
 MP3 s = new MP3();
 Thread t1 = new Thread(s);
 t1.start();
 s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

class xiugai extends JFrame {
 public xiugai() {
  jl1 = new JLabel("文件名");
  jt1 = new JTextField(20);
  jl2 = new JLabel("文件路徑");
  jt2 = new JTextField(20);
  xiugai = new JButton("修改");
  Container c = getContentPane();
  c.setLayout(new GridLayout(3, 1));
  JPanel j1 = new JPanel();
  JPanel j2 = new JPanel();
  JPanel j3 = new JPanel();
  j1.add(jl1);
  j1.add(jt1);
  j2.add(jl2);
  j2.add(jt2);
  j3.add(xiugai);
  c.add(j1);
  c.add(j2);
  c.add(j3);
  xiugai.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent event) {
   mingcheng.setElementAt(jt1.getText(), jl.getSelectedIndex());
   vector.setElementAt(jt2.getText(), jl.getSelectedIndex());
   jl.setListData(mingcheng);
   dispose();
  }
  });
  setSize(300, 120);
  setVisible(true);
 }
}
}

class lujin implements Serializable {

Vector a = new Vector();

Vector b = new Vector();

public lujin(Vector vector, Vector mingcheng) {
 a = vector;
 b = mingcheng;
}

}


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

相關(guān)文章

  • Spring中Properties的配置方式

    Spring中Properties的配置方式

    這篇文章主要介紹了Spring中Properties的配置方式,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-02-02
  • MyBatis圖文并茂講解注解開發(fā)一對(duì)一查詢

    MyBatis圖文并茂講解注解開發(fā)一對(duì)一查詢

    這篇文章主要介紹了SpringBoot中Mybatis注解一對(duì)一查詢的實(shí)現(xiàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • Windows下Java調(diào)用可執(zhí)行文件代碼實(shí)例

    Windows下Java調(diào)用可執(zhí)行文件代碼實(shí)例

    這篇文章主要介紹了Windows下Java調(diào)用可執(zhí)行文件代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-12-12
  • 淺談java中math類中三種取整函數(shù)的區(qū)別

    淺談java中math類中三種取整函數(shù)的區(qū)別

    下面小編就為大家?guī)硪黄獪\談java中math類中三種取整函數(shù)的區(qū)別。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-11-11
  • Mybatis返回類型為Map時(shí)遇到的類型轉(zhuǎn)化的異常問題

    Mybatis返回類型為Map時(shí)遇到的類型轉(zhuǎn)化的異常問題

    這篇文章主要介紹了Mybatis返回類型為Map時(shí)遇到的類型轉(zhuǎn)化的異常問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • java?Springboot實(shí)現(xiàn)教務(wù)管理系統(tǒng)

    java?Springboot實(shí)現(xiàn)教務(wù)管理系統(tǒng)

    這篇文章主要介紹了java?Springboot實(shí)現(xiàn)教務(wù)管理系統(tǒng)的過程,文章圍繞實(shí)現(xiàn)過程展開全文詳細(xì)內(nèi)容,具有一定的參考價(jià)值,需要的朋友可以參考一下,希望對(duì)你有所幫助
    2021-11-11
  • Java之SpringCloud Eurka注冊(cè)錯(cuò)誤解決方案

    Java之SpringCloud Eurka注冊(cè)錯(cuò)誤解決方案

    這篇文章主要介紹了Java之SpringCloud Eurka注冊(cè)錯(cuò)誤解決方案,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • SpringBoot添加License的多種方式

    SpringBoot添加License的多種方式

    License指的是版權(quán)許可證,當(dāng)我們開發(fā)完系統(tǒng)后,如果不想讓用戶一直白嫖使用,比如說按時(shí)間續(xù)費(fèi),License的作用就有了。我們可以給系統(tǒng)指定License的有效期,控制系統(tǒng)的可用時(shí)間。
    2021-06-06
  • SpringCloud?Function?SpEL注入漏洞分析及環(huán)境搭建

    SpringCloud?Function?SpEL注入漏洞分析及環(huán)境搭建

    SpringCloud 是一套分布式系統(tǒng)的解決方案,常見的還有阿里巴巴的Dubbo,F(xiàn)ass的底層實(shí)現(xiàn)就是函數(shù)式編程,SpringCloud Function 就是Spring提供的分布式函數(shù)式編程組件,下面給大家介紹下SpringCloud?Function?SpEL注入漏洞分析,感興趣的朋友一起看看吧
    2022-04-04
  • java == 引發(fā)的線上異常詳解

    java == 引發(fā)的線上異常詳解

    這篇文章主要介紹了java == 引發(fā)的線上異常,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2021-09-09

最新評(píng)論

县级市| 潜山县| 张掖市| 贵州省| 乌拉特中旗| 将乐县| 新龙县| 化隆| 大冶市| 泰来县| 澎湖县| 威远县| 广宗县| 崇明县| 平远县| 麦盖提县| 江门市| 红河县| 安平县| 塔河县| 衡山县| 海南省| 延长县| 民丰县| 晋州市| 屏南县| 上虞市| 集安市| 乐亭县| 耿马| 阜新| 青海省| 榆社县| 扬中市| 德格县| 东乌珠穆沁旗| 元阳县| 安吉县| 周至县| 泌阳县| 永济市|