为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

音乐播放器基本设计(附源码)

2018-01-04 50页 doc 231KB 14阅读

用户头像

is_105949

暂无简介

举报
音乐播放器基本设计(附源码)音乐播放器基本设计(附源码) 音乐播放器;附源乐, 只要源乐中所有的乐都乐制到自己定乐的乐目里就乐的~将 数据乐乐乐, 歌曲乐型表,乐型乐、乐型名号称 歌曲信息表,歌曲乐、歌曲名、歌手、作曲、文件位置、乐型乐号号播放器界面, 主界面(1) 添加歌曲界面(2) 添加歌曲乐型(3) 乐找(4) 功能描述, 播放,乐播放列表中的歌曲乐行播放~播放乐乐歌曲的信息乐示的右乐的歌曲信息面双会将1. 板中~同乐匹配歌乐~把相乐的歌乐乐示在右乐的歌乐面板中。会 停止,在歌曲列表下方有一小按乐~歌曲正在播放乐~乐示的是可停止的按乐~点...
音乐播放器基本设计(附源码)
音乐播放器基本(附源码) 音乐播放器;附源乐, 只要源乐中所有的乐都乐制到自己定乐的乐目里就乐的~将 数据乐乐乐, 歌曲乐型表,乐型乐、乐型名号称 歌曲信息表,歌曲乐、歌曲名、歌手、作曲、文件位置、乐型乐号号播放器界面, 主界面(1) 添加歌曲界面(2) 添加歌曲乐型(3) 乐找(4) 功能描述, 播放,乐播放列表中的歌曲乐行播放~播放乐乐歌曲的信息乐示的右乐的歌曲信息面双会将1. 板中~同乐匹配歌乐~把相乐的歌乐乐示在右乐的歌乐面板中。会 停止,在歌曲列表下方有一小按乐~歌曲正在播放乐~乐示的是可停止的按乐~点乐乐个当2. 停止前播放的歌曲。当 添加歌曲乐,在播放列表中乐乐右乐~乐乐添加歌曲乐型乐乐出一添加歌曲乐型的乐~在乐乐个会框会3. 框填确号中上正的信息;歌曲乐型乐不能重乐,后提交~乐乐出“添加成功”的消息提示~ 否乐乐出“添加失乐”的相乐信息。 添加歌曲, 乐中歌曲乐型后~乐乐右乐乐乐添加歌曲或者点乐左下角的添加按乐乐乐出一添加歌个4. 曲信息的乐~乐入歌曲信息;歌名不能重乐,后点乐提交乐乐行添加~添加成功乐更新会框填 了歌曲列表~否乐乐出相乐的提示~如,框。 乐除歌曲,乐中歌曲后~乐乐右乐乐乐乐除歌曲或者点乐左下角的乐除乐乐出乐乐,确框5. ~乐乐“是”乐乐除~否乐无操作。 乐除歌曲乐型,乐中要乐除的歌曲乐型~乐乐右乐乐除歌曲乐型~乐乐出乐乐~乐中“是”乐乐除~否确框6. 乐无操作。 乐,点乐左下角的乐~乐出一乐入~乐入歌名的一部分;包含歌名,乐行乐~乐找找会个框找找7. 到的歌曲乐示在乐入上方~点乐乐到的歌曲乐行播放会框找 ,添加歌曲乐型乐~乐型乐和名都不能乐空~号称注 添加歌曲乐~歌曲名不能乐空~歌曲地址不能乐空;否乐播放乐是无效路,~若乐空~会径 会乐出相乐的提示信息 乐的描述, 乐号乐名功能描述 ,主界面乐~播放器的入口PlayerFrame.java ,添加歌曲信息AddSongInfoDialog.java,添加歌曲乐型AddSongInfoTypeDialog.java,封了播放、停止的方法装PlayerUtil.java ,乐播放器相乐的鼠乐乐器听PlayerMouseListener.java,乐播放器主界面相乐的按乐乐器听PlayerActionListener.java!乐的乐入的文乐乐器找框档听PlayerDocumentListener.java,添加歌曲信息界面的按乐乐器听AddSongInfoActionListener.java,添加歌曲乐型界面的按乐乐器听AddSongTypeActionListener.java 封了乐接和乐放据乐装数10DBConnection.java 封了乐据乐的操作;增、乐、改、乐,装数11JDBCHelper.java 操作据乐的乐句;常量,数12SQLContants.java 自定乐的唯一乐束的常异13UniqueException.java 歌曲信息据乐乐乐象;接口,数14SongInfoDao.java 15SongInfoDaoImpl.javaSongInfoDao.java的乐乐乐具的每乐中的方法的作用乐源代乐中的注乐体个 主界面,1.PlayerFrame.java package cn.xtu.catqq.view.player;/** 音乐播放器主界面* V1.0 * */ import java.awt.BorderLayout;import java.awt.Color; import java.awt.Font; import java.awt.GridLayout;import java.awt.Insets; import java.math.BigDecimal;import java.util.ArrayList;import java.util.List; import java.util.Vector; import javax.swing.Icon; import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JPopupMenu;import javax.swing.JScrollPane;import javax.swing.JSlider; import javax.swing.JSplitPane; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.SwingConstants; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeModel; import cn.xtu.catqq.control.playerlistener.PlayerActionListener;import cn.xtu.catqq.control.playerlistener.PlayerDocumentListener; import cn.xtu.catqq.control.playerlistener.PlayerMouseListener;import cn.xtu.catqq.model.player.SongInfoDao;import cn.xtu.catqq.model.player.impl.SongInfoDaoImpl;import cn.xtu.catqq.util.FontUtil; import cn.xtu.catqq.util.InitialFrameStyle; import cn.xtu.catqq.util.MyTreeUI; public class PlayerFrame extends JFrame { /* 歌曲信息面板右乐 * songInfoPanel:() 播放乐度面板条 * playerPanel: 播放的乐度条 * sliderPanel: 歌乐面板 * songWordsPanel: 乐乐面板 * queryPanel: */ private JPanel leftPanel, rightPanel, songInfoPanel, sliderPanel, songWordsPanel, queryPanel; /* 用存放歌乐来 * songLrc: */ private Vector songLrc = new Vector();/* 定乐乐片几个 * */ 播放private Icon playIcon = new ImageIcon("img\\.png"); 停止private Icon stopIcon = new ImageIcon("img\\.png"); private JSlider slider; private JLabel songWordsLabel1, songWordsLabel2, songWordsLabel3, songWordsLabel4, songWordsLabel5; /* 添加歌曲按乐 乐除歌曲按乐 根据歌曲名乐乐歌 * btnAddSong:btnDelSong:querySongInfo: 曲信息按乐 */ private JButton btnAddSong, btnDelSong, btnQuerySong, btnPlay; private List btnList = new ArrayList();private PlayerMouseListener pmLis; private Thread mouseThread; /* 用建来构 * treeModel:JTree */ private DefaultTreeModel treeModel; private JTree tree; private JScrollPane scrollPanel, queryScrollPanel;/* 用乐入歌曲名的文本 来框用乐示歌曲名的文本来框 * txtQuery:txtSongName: 用乐示歌手的文本来框txtSonger: 用乐示作曲者 来乐示歌曲乐型 乐示歌曲地址 * txtMS:txtSongType:txtSongLoc: */ private JTextField txtQuery, txtSongName, txtSonger, txtMS, txtSongType, txtSongLoc; private JPopupMenu popMenu, findPopMenu;private JMenuItem miAddSong, miAddSongType, miDelSong, miDelSongType; private Insets insets = new Insets(0, 0, 0, 0);public PlayerFrame() { 音乐播放器this.setTitle("V1.0"); InitialFrameStyle.setFrameStyle(this, 800, 600); initialComponent(); createPopedMunu(); createFindPopMenu(); registerListener(); this.validate(); } 初始化面板乐件// private void initialComponent() { JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);splitPane.setDividerLocation(200); splitPane.setDividerSize(2); leftPanel = new JPanel(null); JPanel northPanel = new JPanel(null); 播放器左上JLabel lab = new JLabel(new ImageIcon("img\\.png")); InitialFrameStyle.putComponentByNull(northPanel, lab, 0, 0, 200, 100);InitialFrameStyle.putComponentByNull(leftPanel, northPanel, 0, 0, 200, 100); 乐乐面板// queryScrollPanel = new JScrollPane(); queryScrollPanel.setVisible(false); queryPanel = new JPanel(); queryScrollPanel.setViewportView(queryPanel); InitialFrameStyle.putComponentByNull(leftPanel, queryScrollPanel, 0, 405, 200, 100); 初始化左乐的滑乐面板// scrollPanel = new JScrollPane(); initialScrollPane(); InitialFrameStyle.putComponentByNull(leftPanel, scrollPanel, 0, 100, 200, 410); 滑乐面板条// sliderPanel = new JPanel(null); sliderPanel.setBackground(new Color(1, 141, 255)); btnPlay = new JButton(playIcon); btnPlay.setActionCommand("stop"); btnPlay.setMargin(insets); InitialFrameStyle.putComponentByNull(sliderPanel, btnPlay, 3, 5, 15, 15);slider = new JSlider(0, 100, 0); slider.setBackground(new Color(1, 141, 255)); InitialFrameStyle.putComponentByNull(sliderPanel, slider, 20, 5, 180, 15);InitialFrameStyle.putComponentByNull(leftPanel, sliderPanel, 0, 506, 200, 20);左乐下面的面板// JPanel southPanel = new JPanel(null); southPanel.setBackground(new Color(1, 141, 255)); southPanel.setBounds(0, 527, 200, 45);initLeftSouthPanel(southPanel); leftPanel.add(southPanel); splitPane.setLeftComponent(leftPanel);rightPanel = new JPanel(null); 音乐信息JLabel label = new JLabel(""); label.setFont(FontUtil.setFont(60));label.setForeground(Color.ORANGE);InitialFrameStyle.putComponentByNull(rightPanel, label, 150, 50, 300, 50); initialRightPanel(); 音乐播放器背景JLabel backGround = new JLabel(new ImageIcon("img\\.jpg"));backGround.setBounds(0, 0, 600, 600);rightPanel.add(backGround); splitPane.setRightComponent(rightPanel);this.add(splitPane); } 初始化右乐的面板// private void initialRightPanel() {歌曲信息面板// songInfoPanel = new JPanel(); songInfoPanel.setBorder(new TitledBorder(new LineBorder(Color.ORANGE), 歌曲信息"")); initialSongInfoPanel(); 歌乐面板// initialSongWordsPanel(); InitialFrameStyle.putComponentByNull(rightPanel, songInfoPanel, 30, 120, 520, 160); InitialFrameStyle.putComponentByNull(rightPanel, songWordsPanel, 30, 300, 520, 220); } 初始化歌曲信息面板// private void initialSongInfoPanel() {songInfoPanel.setLayout(null); songInfoPanel.setBackground(Color.WHITE); 歌曲名JLabel lblSongName = new JLabel(":"); 歌 手JLabel lblSonger = new JLabel(":"); 作 曲JLabel lblMS = new JLabel(":"); 乐 型JLabel lblSongType = new JLabel(":"); 位 置JLabel lblSongLoc = new JLabel(":"); Font font = FontUtil.setFont(14); lblSongName.setFont(font); lblSonger.setFont(font); lblMS.setFont(font); lblSongType.setFont(font); lblSongLoc.setFont(font); txtSongName = new JTextField(15); txtSongName.setBorder(new LineBorder(null, 0));txtSongName.setBackground(new Color(255,255,255));txtSongName.setEditable(false); txtSonger = new JTextField(15); txtSonger.setBorder(new LineBorder(null, 0));txtSonger.setBackground(new Color(255,255,255));txtSonger.setEditable(false); txtMS = new JTextField(15); txtMS.setBorder(new LineBorder(null, 0));txtMS.setBackground(new Color(255,255,255));txtMS.setEditable(false); txtSongType = new JTextField(15); txtSongType.setBorder(new LineBorder(null, 0));txtSongType.setBackground(new Color(255,255,255));txtSongType.setEditable(false); txtSongLoc = new JTextField(15); txtSongLoc.setBorder(new LineBorder(null, 0));txtSongLoc.setBackground(new Color(255,255,255));txtSongLoc.setEditable(false); InitialFrameStyle.putComponentByNull(songInfoPanel, lblSongName, 80, 40, 50, 25); InitialFrameStyle.putComponentByNull(songInfoPanel, lblSonger, 300, 40, 50, 25); InitialFrameStyle.putComponentByNull(songInfoPanel, lblMS, 80, 70, 50, 25); InitialFrameStyle.putComponentByNull(songInfoPanel, lblSongType, 300, 70, 50, 25); InitialFrameStyle.putComponentByNull(songInfoPanel, lblSongLoc, 80, 100, 50, 25); InitialFrameStyle.putComponentByNull(songInfoPanel, txtSongName, 135, 40, 150, 25); InitialFrameStyle.putComponentByNull(songInfoPanel, txtSonger, 355, 40, 150, 25); InitialFrameStyle.putComponentByNull(songInfoPanel, txtMS, 135, 70, 150, 25); InitialFrameStyle.putComponentByNull(songInfoPanel, txtSongType, 355, 70, 150, 25); InitialFrameStyle.putComponentByNull(songInfoPanel, txtSongLoc, 135, 100, 370, 25); } 初始化歌乐面板// private void initialSongWordsPanel() { songWordsPanel = new JPanel(new GridLayout(5, 1)); songWordsPanel.setBorder(new TitledBorder(new LineBorder(Color.ORANGE, 歌乐1), "")); songWordsLabel1 = new JLabel(); songWordsLabel1.setHorizontalAlignment(SwingConstants.CENTER);songWordsLabel1.setFont(FontUtil.setFont(14)); songWordsLabel1.setForeground(new Color(38, 99, 224));songWordsLabel2 = new JLabel(); songWordsLabel2.setHorizontalAlignment(SwingConstants.CENTER);songWordsLabel2.setFont(FontUtil.setFont(18)); songWordsLabel2.setForeground(new Color(38, 99, 224));songWordsLabel3 = new JLabel(); songWordsLabel3.setHorizontalAlignment(SwingConstants.CENTER);songWordsLabel3.setFont(FontUtil.setFont(22)); songWordsLabel3.setForeground(Color.MAGENTA); songWordsLabel4 = new JLabel(); songWordsLabel4.setHorizontalAlignment(SwingConstants.CENTER);songWordsLabel4.setFont(FontUtil.setFont(18)); songWordsLabel4.setForeground(new Color(38, 99, 224));songWordsLabel5 = new JLabel(); songWordsLabel5.setHorizontalAlignment(SwingConstants.CENTER);songWordsLabel5.setFont(FontUtil.setFont(14)); songWordsLabel5.setForeground(new Color(38, 99, 224)); songWordsPanel.add(songWordsLabel1); songWordsPanel.add(songWordsLabel2); songWordsPanel.add(songWordsLabel3); songWordsPanel.add(songWordsLabel4); songWordsPanel.add(songWordsLabel5); } 初始化左乐乐乐面板存放// JTree private void initialScrollPane() { 所有音乐DefaultMutableTreeNode root = new DefaultMutableTreeNode(""); treeModel = new DefaultTreeModel(root); SongInfoDao infoDao = new SongInfoDaoImpl();List songTypes = infoDao.findSongList();for (int i = 0; i < songTypes.size(); i++) { StringBuffer sb = new StringBuffer(); Object[] tempSongTypes = songTypes.get(i); sb.append(tempSongTypes[0]); sb.append(":"); sb.append(tempSongTypes[1]); DefaultMutableTreeNode typeName = new DefaultMutableTreeNode(sb .toString()); treeModel.insertNodeInto(typeName, root, root.getChildCount()); BigDecimal tempTypeId = (BigDecimal) tempSongTypes[0]; int typeId = tempTypeId.intValue(); List songNames = infoDao.findSongName(typeId); for (int j = 0; j < songNames.size(); j++) { String songName = (String) songNames.get(j)[0]; DefaultMutableTreeNode music1 = new DefaultMutableTreeNode( songName); treeModel.insertNodeInto(music1, typeName, typeName .getChildCount()); } } tree = new JTree(treeModel); tree.setUI(new MyTreeUI()); 乐置是否乐示根乐点的操作// tree.setShowsRootHandles(false); tree.setRootVisible(false); tree.setOpaque(true); 乐置乐乐次数// tree.setToggleClickCount(1); 乐用乐的渲染器// 歌曲InitialFrameStyle.InitialTree(tree, "img\\.png"); scrollPanel.setViewportView(tree); } private void createPopedMunu() { popMenu = new JPopupMenu(); 初始化菜乐乐// 添加歌曲miAddSong = new JMenuItem("(A)"); 添加歌曲乐型miAddSongType = new JMenuItem("(B)"); 乐除歌曲miDelSong = new JMenuItem("(C)"); 乐除歌曲乐型miDelSongType = new JMenuItem("(D)"); 乐每菜乐乐乐置乐名个// miAddSong.setActionCommand("addSongInfo");miAddSongType.setActionCommand("addSongType");miDelSong.setActionCommand("delSong");miDelSongType.setActionCommand("delSongType");乐置右乐性的字和字属体号// Font font = FontUtil.setFont(12); miAddSong.setFont(font); miAddSongType.setFont(font); miDelSong.setFont(font); miDelSongType.setFont(font); 乐右乐性添加快捷乐属// miAddSong.setMnemonic('A'); miAddSongType.setMnemonic('B'); miDelSong.setMnemonic('C'); miDelSongType.setMnemonic('D'); 将菜乐乐添加到乐出菜乐中// popMenu.add(miAddSong); popMenu.add(miAddSongType); popMenu.add(miDelSong); popMenu.add(miDelSongType); } 初始化左乐面板的南部;三按乐,个// private void initLeftSouthPanel(JPanel southPanel) { 添加添加btnAddSong = new JButton("", new ImageIcon("img\\.png"));btnAddSong.setBackground(new Color(1, 141, 255));btnAddSong.setBorder(new LineBorder(null, 0));btnAddSong.setActionCommand("addSongInfo");btnAddSong.setFont(FontUtil.setFont(12)); btnAddSong.setMargin(insets); 乐除乐除btnDelSong = new JButton("", new ImageIcon("img\\.png")); btnDelSong.setBackground(new Color(1, 141, 255));btnDelSong.setBorder(new LineBorder(null, 0));btnDelSong.setActionCommand("delSong");btnDelSong.setMargin(insets); btnDelSong.setFont(FontUtil.setFont(12)); 乐找乐找btnQuerySong = new JButton("", new ImageIcon("img\\.png")); btnQuerySong.setBackground(new Color(1, 141, 255));btnQuerySong.setBorder(new LineBorder(null, 0));btnQuerySong.setActionCommand("querySong");btnQuerySong.setMargin(insets); btnQuerySong.setFont(FontUtil.setFont(12));InitialFrameStyle.putComponentByNull(southPanel, btnAddSong, 5, 8, 60, 25); InitialFrameStyle.putComponentByNull(southPanel, btnDelSong, 70, 8, 60, 25); InitialFrameStyle.putComponentByNull(southPanel, btnQuerySong, 135, 8, 60, 25); } 构找建乐的乐出菜乐// private void createFindPopMenu() { findPopMenu = new JPopupMenu(); findPopMenu.setLayout(new BorderLayout());txtQuery = new JTextField(17); findPopMenu.add(txtQuery); } 注乐乐器册听// private void registerListener() { pmLis = new PlayerMouseListener(this); 鼠乐mouseThread = new Thread(pmLis, ""); mouseThread.start(); tree.addMouseListener(pmLis); PlayerActionListener paLis = new PlayerActionListener(this); btnAddSong.addActionListener(paLis); btnDelSong.addActionListener(paLis); btnQuerySong.addActionListener(paLis); miAddSong.addActionListener(paLis); miAddSongType.addActionListener(paLis); miDelSong.addActionListener(paLis); miDelSongType.addActionListener(paLis); btnPlay.addActionListener(paLis); PlayerDocumentListener docLis = new PlayerDocumentListener(this); txtQuery.getDocument().addDocumentListener(docLis); } public JTextField getTxtQuery() { return txtQuery; } public JPopupMenu getFindPopMenu() { return findPopMenu; } public DefaultTreeModel getTreeModel() { return treeModel; } public JTree getTree() { return tree; } public JButton getBtnAddSong() { return btnAddSong; } public JButton getBtnDelSong() { return btnDelSong; } public JTextField getTxtSongName() { return txtSongName; } public JTextField getTxtSonger() { return txtSonger; } public JTextField getTxtMS() { return txtMS; } public JTextField getTxtSongType() { return txtSongType; } public JTextField getTxtSongLoc() { return txtSongLoc; } public void setTreeModel(DefaultTreeModel treeModel) { this.treeModel = treeModel;} public JPanel getSongInfoPanel() { return songInfoPanel; } public JPopupMenu getPopMenu() { return popMenu; } public Vector getSongLrc() { return songLrc; } public JSlider getSlider() { return slider; } public Icon getPlayIcon() { return playIcon; } public JButton getBtnPlay() { return btnPlay; } public void setBtnPlay(JButton btnPlay) { this.btnPlay = btnPlay; } public Icon getStopIcon() { return stopIcon; } public JLabel getSongWordsLabel1() { return songWordsLabel1; } public JLabel getSongWordsLabel2() { return songWordsLabel2; } public JLabel getSongWordsLabel3() { return songWordsLabel3; } public JLabel getSongWordsLabel4() { return songWordsLabel4; } public JLabel getSongWordsLabel5() { return songWordsLabel5; } public JPanel getQueryPanel() { return queryPanel; } public JScrollPane getQueryScrollPanel() { return queryScrollPanel; } public List getBtnList() { return btnList; } public PlayerMouseListener getPmLis() { return pmLis; } public Thread getMouseThread() { return mouseThread; } public static void main(String[] args) { new PlayerFrame().setVisible(true); } } 添加歌曲信息2. package cn.xtu.catqq.view.player; import java.awt.Color; import java.awt.Insets; import java.util.List; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JTextField; import cn.xtu.catqq.control.playerlistener.AddSongInfoActionListener; import cn.xtu.catqq.model.player.SongInfoDao;import cn.xtu.catqq.model.player.impl.SongInfoDaoImpl; import cn.xtu.catqq.util.FontUtil; import cn.xtu.catqq.util.InitialFrameStyle;public class AddSongInfoDialog extends JDialog {/* 歌曲名 * txtSongName: 歌手 * txtSonger: 作曲 * txtMS: 文件位置 * txtSongLoc: */ private JTextField txtSongName,txtSonger,txtMs,txtSongLoc; 歌曲乐型下拉框// private JComboBox boxSongType; /* 乐乐文件 * btnBrowse: 确乐提交按乐 * btnConfirm: 取消按乐 * btnCancel: */ private JButton btnBrowse,btnConfirm,btnCancel;用存乐歌曲信息来歌曲乐号歌曲名歌手作曲歌曲乐型文件位置//(, , , , , ) private List songInfo; public AddSongInfoDialog(List songInfo){ 添加歌曲信息InitialFrameStyle.setDialogStyle(this, "", 500, 400); this.setLayout(null); initialComponent(); registerListener(); this.songInfo = songInfo; } 初始化乐乐乐的乐件会框// private void initialComponent(){ 歌曲信息JLabel labTitle = new JLabel(""); labTitle.setForeground(Color.ORANGE); labTitle.setFont(FontUtil.setFont(40)); InitialFrameStyle.putComponentByNull(this, labTitle, 170, 30, 200, 50); 歌 名JLabel lblSongName = new JLabel(":"); 歌 手JLabel lblSonger = new JLabel(":"); 作 曲JLabel lblMS = new JLabel(":"); 乐 型JLabel lblSongType = new JLabel(":"); 位 置JLabel lblSongLoc = new JLabel(":"); InitialFrameStyle.putComponentByNull(this, lblSongName, 140, 100, 50, 25); InitialFrameStyle.putComponentByNull(this, lblSonger, 140, 140, 50, 25); InitialFrameStyle.putComponentByNull(this, lblMS, 140, 180, 50, 25); InitialFrameStyle.putComponentByNull(this, lblSongType, 140, 220, 50, 25); InitialFrameStyle.putComponentByNull(this, lblSongLoc, 140, 260, 50, 25); txtSongName=new JTextField(15); txtSonger=new JTextField(15); txtMs=new JTextField(15); SongInfoDao infoDao = new SongInfoDaoImpl();List songTypes = infoDao.findSongList();int len = songTypes.size(); Object[] types = new Object[len]; for(int i=0; i getSongInfo() { return songInfo; } public void setSongInfo(List songInfo) { this.songInfo = songInfo; } /** * @param args */ public static void main(String[] args) { new AddSongInfoDialog(null).setVisible(true); } } 添加歌曲乐型,3. package cn.xtu.catqq.view.player;/** 添加歌曲乐型的乐乐会框* */ import java.awt.Color; import java.awt.Insets; import javax.swing.ImageIcon;import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JTextField; import cn.xtu.catqq.control.playerlistener.AddSongTypeActionListener; import cn.xtu.catqq.util.FontUtil; import cn.xtu.catqq.util.InitialFrameStyle;public class AddSongInfoTypeDialog extends JDialog { /* 歌曲乐号 * txtTypeId: 歌曲乐型名 * txtTypeName: */ private JTextField txtTypeId, txtTypeName;/* 添加的按乐取消的按乐 * btnAdd:, btnCancel: */ private JButton btnAdd, btnCancel;主界面// private PlayerFrame playerFrame; public AddSongInfoTypeDialog(PlayerFrame playerFrame) { 添加歌曲乐型InitialFrameStyle.setDialogStyle(this, "", 400, 300); this.setLayout(null); initialComponent(); registerListener(); this.playerFrame = playerFrame; } 初始化乐乐乐的乐件会框// private void initialComponent() { 歌曲乐型JLabel lblTitle = new JLabel(""); lblTitle.setForeground(Color.MAGENTA); lblTitle.setFont(FontUtil.setFont(40)); 乐型乐号JLabel lblTypeId = new JLabel(":"); lblTypeId.setFont(FontUtil.setFont(15)); 乐型名称JLabel lblTypeName = new JLabel(":"); lblTypeName.setFont(FontUtil.setFont(15)); txtTypeId = new JTextField(15); txtTypeName = new JTextField(15); Insets insets = new Insets(0, 0, 0, 0); btnAdd = new JButton(new ImageIcon("img\\submit1.png")); btnAdd.setActionCommand("add"); btnAdd.setMargin(insets); btnCancel = new JButton(new ImageIcon("img\\cancel1.png")); btnCancel.setActionCommand("cancel"); btnCancel.setMargin(insets); 添加歌曲乐型背景JLabel lblImg = new JLabel(new ImageIcon("img\\.jpg")); InitialFrameStyle.putComponentByNull(this, lblTitle, 110, 30, 180, 50); InitialFrameStyle.putComponentByNull(this, lblTypeId, 90, 100, 70, 30); InitialFrameStyle .putComponentByNull(this, txtTypeId, 160, 100, 140, 30); InitialFrameStyle .putComponentByNull(this, lblTypeName, 90, 150, 70, 30); InitialFrameStyle.putComponentByNull(this, txtTypeName, 160, 150, 140, 30); InitialFrameStyle.putComponentByNull(this, btnAdd, 100, 200, 80, 35); InitialFrameStyle.putComponentByNull(this, btnCancel, 200, 200, 80, 35); InitialFrameStyle.putComponentByNull(this, lblImg, 0, 0, 400, 300);} 注乐乐器册听// private void registerListener(){ AddSongTypeActionListener ataLis = new AddSongTypeActionListener(this); btnAdd.addActionListener(ataLis); btnCancel.addActionListener(ataLis); } public JTextField getTxtTypeId() { return txtTypeId; } public void setTxtTypeId(JTextField txtTypeId) { this.txtTypeId = txtTypeId; } public JTextField getTxtTypeName() { return txtTypeName; } public void setTxtTypeName(JTextField txtTypeName) { this.txtTypeName = txtTypeName; } public PlayerFrame getPlayerFrame() { return playerFrame; } public void setPlayerFrame(PlayerFrame playerFrame) { this.playerFrame = playerFrame; } } 4.PlayerUtil.java package cn.xtu.catqq.util; /** 封了播放和停止方法装* */ import java.io.File; import java.io.FileReader; import java.util.EventListener; import java.util.List; import java.util.Vector; import javax.media.bean.playerbean.MediaPlayer;import cn.xtu.catqq.control.playerlistener.PlayerMouseListener; import cn.xtu.catqq.view.player.PlayerFrame;public class PlayerUtil { private MediaPlayer player = new MediaPlayer();private int totalTime, minutes, seconds;private Vector songLrc; private PlayerFrame playerFrame; private boolean isPlay; private PlayerMouseListener mouseLis; public PlayerUtil(MediaPlayer player, PlayerFrame playerFrame, EventListener listener) { this.player = player; this.playerFrame = playerFrame; mouseLis = (PlayerMouseListener) listener;} 播放// @SuppressWarnings("deprecation") public void play(String playSongName, String songLoc) { int len = songLoc.length(); String lrcLoc = songLoc.substring(0, len - 3) + "lrc"; File songFile = new File(songLoc); songLrc = playerFrame.getSongLrc(); if (songFile.exists() && songLoc.matches("[\\S\\s]*.mp3")) { String selectedSongName = ""; if (mouseLis != null) { selectedSongName = mouseLis.getSelectedNodeName(); } 播if (!playSongName.equals(selectedSongName) || "img\\ 放.png".equals(playerFrame.getBtnPlay().getIcon().toString())) { player.stop(); playerFrame.getMouseThread().resume(); playerFrame.getBtnPlay().setIcon(playerFrame.getStopIcon()); playerFrame.getSongWordsLabel1().setText(""); playerFrame.getSongWordsLabel2().setText(""); playerFrame.getSongWordsLabel3().setText(""); playerFrame.getSongWordsLabel4().setText(""); playerFrame.getSongWordsLabel5().setText(""); if (mouseLis != null) { mouseLis.setMinutes(0); mouseLis.setSeconds(0); } player.setMediaLocation("file:" + songLoc); songLrc.clear(); songLrc = saveSongLrc(lrcLoc); if (songLrc.size() == 0) { 未到相乐的歌乐找playerFrame.getSongWordsLabel2().setText(""); } player.start(); split(); isPlay = true; } else { stop(); } } } 停止// @SuppressWarnings("deprecation") public void stop(){ player.stop(); playerFrame.getBtnPlay().setIcon(playerFrame.getPlayIcon()); playerFrame.getSongWordsLabel1().setText("");playerFrame.getSongWordsLabel2().setText("");playerFrame.getSongWordsLabel3().setText("");playerFrame.getSongWordsLabel4().setText("");playerFrame.getSongWordsLabel5().setText(""); playerFrame.getSlider().setValue(0);if (mouseLis != null) { mouseLis.setMinutes(0); mouseLis.setSeconds(0); } 需要停止前乐程~当乐用无效~使用乐方法代替~使得乐程中断//stop()stop()playerFrame.getMouseThread().suspend();} 将划乐乐乐分成分和秒// public void split() { do { try { Thread.sleep(500); } catch (InterruptedException ew) { } totalTime = (int) player.getDuration().getSeconds(); } while (totalTime > 10000);int aaa = totalTime; minutes = (int) aaa / 60; seconds = (int) aaa % 60; } 把歌乐乐取出存放到一来个里// Vector public Vector saveSongLrc(String url) { Vector resultLrc = new Vector(); try { FileReader in = new FileReader(url); int a = 0; String str = ""; while ((a = in.read()) != -1) { if ((char) a != '\n') { str += (char) a; } else if ((char) a == '\n') { resultLrc.add(str); str = ""; } } } catch (Exception e) { 歌乐乐取常异System.out.println(""); } return resultLrc; } 得到每一句歌乐~不包括乐乐// public StringBuffer getEverySong(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 setSongInfoToPlayerFrame(List result) { Object[] obj = result.get(0); playerFrame.getTxtSongName().setText(obj[1].toString()); playerFrame.getTxtSonger().setText(obj[2].toString()); playerFrame.getTxtMS().setText(obj[3].toString()); playerFrame.getTxtSongLoc().setText(obj[4].toString()); playerFrame.getTxtSongType().setText(obj[5].toString());} public boolean isPlay() { return isPlay; } public void setPlay(boolean isPlay) { this.isPlay = isPlay; } public int getTotalTime() { return totalTime; } public void setTotalTime(int totalTime) { this.totalTime = totalTime; } public int getMinutes() { return minutes; } public void setMinutes(int minutes) { this.minutes = minutes; } public int getSeconds() { return seconds; } public void setSeconds(int seconds) { this.seconds = seconds; } public Vector getSongLrc() { return songLrc; } public void setSongLrc(Vector songLrc) { this.songLrc = songLrc; } } 5.PlayerMouseListener.java package cn.xtu.catqq.control.playerlistener;/** 音乐播放器主界面的鼠乐乐器~乐主界面听双中得乐点可以播放* JTree */ import java.awt.Color; import java.awt.Component; import java.awt.event.MouseEvent; import java.awt.event.MouseListener;import java.util.List; import java.util.Vector; import javax.media.bean.playerbean.MediaPlayer;import javax.swing.JButton; import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.TreePath; import cn.xtu.catqq.model.player.SongInfoDao;import cn.xtu.catqq.model.player.impl.SongInfoDaoImpl; import cn.xtu.catqq.util.PlayerUtil; import cn.xtu.catqq.view.player.PlayerFrame;public class PlayerMouseListener implements Runnable, MouseListener { private PlayerFrame playerFrame; private MediaPlayer player = new MediaPlayer();private PlayerUtil playerUtil; private int seconds, minutes, currentTime, totalTime;private String selectedNodeName; private SongInfoDao infoDao = new SongInfoDaoImpl();构听来造乐乐器的乐象是就乐乐了主界面乐象和存乐播放信息的乐象的引用// public PlayerMouseListener(PlayerFrame playerFrame) { super(); this.playerFrame = playerFrame; playerUtil = new PlayerUtil(player, playerFrame, this);} 乐鼠乐点乐事件听// public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { 左乐乐双// mouseClickEvent(e); } else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) { 右乐性属// playerFrame.getPopMenu().show((Component) e.getSource(), e.getX(), e.getY()); } else if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 1) { if (e.getSource() instanceof JButton) { JButton btn = (JButton) e.getSource(); String btnName = btn.getText(); List result = infoDao.fingSongInfo(btnName); if (result.size() > 0) { 将歌曲信息添加到歌曲信息面板// playerUtil.setSongInfoToPlayerFrame(result); } /* 构从数找建播放器需要的文件位置的乐象据乐中乐到歌曲的文件位置 * */ Object[] songLocObj = infoDao.findSongLoc(btnName).get(0); String songLoc = songLocObj[0].toString(); playerUtil.play("", songLoc); } playerFrame.getQueryScrollPanel().setVisible(false); } } public void mouseEntered(MouseEvent e) { if (e.getSource() instanceof JButton) { JButton btn = (JButton) e.getSource(); btn.setBackground(Color.CYAN); } } public void mouseExited(MouseEvent e) { if (e.getSource() instanceof JButton) { JButton btn = (JButton) e.getSource(); btn.setBackground(Color.WHITE); } } public void mousePressed(MouseEvent e) { if (e.getModifiers() == MouseEvent.META_MASK) { TreePath treePath = playerFrame.getTree().getPathForLocation( e.getX(), e.getY()); if (treePath != null) { playerFrame.getTree().setSelectionPath(treePath); } } } public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub} public int getSeconds() { return seconds; } public void setSeconds(int seconds) { this.seconds = seconds; } public int getMinutes() { return minutes; } public void setMinutes(int minutes) { this.minutes = minutes; } public String getSelectedNodeName() { return selectedNodeName; } public PlayerUtil getPlayerUtil() { return playerUtil; } 鼠乐点乐的操作// private void mouseClickEvent(MouseEvent e) { TreePath treePath = playerFrame.getTree().getPathForLocation(e.getX(), e.getY()); if (treePath != null) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath .getLastPathComponent(); selectedNodeName = treeNode.toString(); String playSongName = playerFrame.getTxtSongName().getText(); List result = infoDao.fingSongInfo(selectedNodeName); if (result.size() > 0) { 将歌曲信息添加到歌曲信息面板// playerUtil.setSongInfoToPlayerFrame(result); /* 构从数找建播放器需要的文件位置的乐象据乐中乐到歌曲的文件位置 * */ Object[] songLocObj = infoDao.findSongLoc(selectedNodeName) .get(0); String songLoc = songLocObj[0].toString(); playerUtil.play(playSongName, songLoc); } } } /** 把歌乐添加到歌乐面板 * 第行歌乐几 * @param i: 乐共有多少行歌乐 * @param size: */ public void putSongWords(int i, int size) { if (i > 1) { String str1 = playerUtil.getEverySong( playerUtil.getSongLrc().get(i - 2)).toString(); playerFrame.getSongWordsLabel1().setText(str1); } if (i > 0) { String str2 = playerUtil.getEverySong( playerUtil.getSongLrc().get(i - 1)).toString(); playerFrame.getSongWordsLabel2().setText(str2); } String str3 = playerUtil.getEverySong(playerUtil.getSongLrc().get(i)) .toString(); playerFrame.getSongWordsLabel3().setText(str3); if (i < size - 1) { String str4 = playerUtil.getEverySong( playerUtil.getSongLrc().get(i + 1)).toString(); playerFrame.getSongWordsLabel4().setText(str4); } if (i < size - 2) { String str5 = playerUtil.getEverySong( playerUtil.getSongLrc().get(i + 2)).toString(); playerFrame.getSongWordsLabel5().setText(str5); } } /** 用控制歌乐歌曲同步来与 * */ public void run() { Vector songLrc = null; while (true) { if (playerUtil.isPlay()) { seconds++; if (playerUtil.getMinutes() == minutes && playerUtil.getSeconds() == seconds) { 播放完// minutes = 0; seconds = 0; player.stop(); playerUtil.setPlay(false); playerFrame.getBtnPlay().setIcon(playerFrame.getPlayIcon()); playerUtil.stop(); break; } if (seconds >= 60) { 播放了一分乐// minutes++; seconds = 0; } if ((seconds + "").length() == 1) { 秒乐一位乐数数// songLrc = playerUtil.getSongLrc(); int size = songLrc.size(); for (int i = 0; i < size; i++) { if (songLrc.get(i).toString().indexOf( "[0" + minutes + ":0" + seconds) >= 0) { putSongWords(i, size); } } } else { int size = songLrc.size(); for (int i = 0; i < size; i++) { if (songLrc.get(i).toString().indexOf( "[0" + minutes + ":" + seconds) >= 0) { putSongWords(i, size); } } } } currentTime = minutes * 60 + seconds;totalTime = playerUtil.getTotalTime();if (totalTime != 0) { int value = currentTime * 100 / totalTime; playerFrame.getSlider().setValue(value);} try { { Thread.sleep(1000); } } catch (InterruptedException ie) {} } } } 6.PlayerActionListener.java package cn.xtu.catqq.control.playerlistener;/** 音乐播放器主界面的按乐乐器听* */ import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import java.util.ArrayList; import java.util.List; import javax.swing.JComboBox; import javax.swing.JOptionPane; import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeModel;import javax.swing.tree.TreePath; import cn.xtu.catqq.model.player.SongInfoDao;import cn.xtu.catqq.model.player.impl.SongInfoDaoImpl;import cn.xtu.catqq.view.player.AddSongInfoDialog;import cn.xtu.catqq.view.player.AddSongInfoTypeDialog;import cn.xtu.catqq.view.player.PlayerFrame;public class PlayerActionListener implements ActionListener { private PlayerFrame playerFrame; private String selectedSongName; 以主界面乐象乐造函的构数参数乐得主界面乐象的引用// , public PlayerActionListener(PlayerFrame playerFrame) { super(); this.playerFrame = playerFrame; } public void actionPerformed(ActionEvent e) { 乐得点乐的按乐的名称// String btnName = e.getActionCommand(); 添加歌曲信息乐除歌曲信息乐除歌曲乐型都需要乐中相乐的乐点乐中的存到中// ,,,path TreePath path = playerFrame.getTree().getSelectionPath();定乐操作据乐的乐象数// SongInfoDao infoDao = new SongInfoDaoImpl();if("stop".equals(btnName)){ playerFrame.getPmLis().getPlayerUtil().stop();} if ("querySong".equals(btnName)) { playerFrame.getTxtQuery().setText(""); playerFrame.getFindPopMenu().show((Component) e.getSource(), -132, -30); } if ("addSongType".equals(btnName)) { 添加歌曲乐型// new AddSongInfoTypeDialog(playerFrame).setVisible(true);} if(path != null) { /* 中父乐点乐 数表示乐乐点乐乐型乐点 表示乐乐点乐歌曲乐点 * len:treePathlen=1:len=2: */ int len = path.getParentPath().getPath().length; DefaultMutableTreeNode songNode = (DefaultMutableTreeNode) path .getLastPathComponent(); String message = null; 乐中的是乐型乐点// if ("addSongInfo".equals(btnName) && len == 1) { 添加歌曲信息// List songInfo = new ArrayList(); AddSongInfoDialog addDialog = new AddSongInfoDialog(songInfo); 将会框乐中的乐型乐置到添加歌曲信息的乐乐中作乐默乐乐// , JComboBox box = addDialog.getBoxSongType(); box.setSelectedItem(songNode.toString()); addDialog.setBoxSongType(box); addDialog.setVisible(true); if (songInfo.size() > 0) { /* 添加完后歌曲信息不乐空乐乐得乐象中得信息并将相乐的信 * ,,songInfo, 息添加到中JTree 包括歌名歌手作曲歌曲乐型文件位置的信息 * songInfo: ,,,, */ String songName = songInfo.get(0).toString(); DefaultMutableTreeNode song = new DefaultMutableTreeNode( songName); DefaultTreeModel model = (DefaultTreeModel) (playerFrame .getTree().getModel()); model.insertNodeInto(song, songNode, songNode .getChildCount()); 刷新playerFrame.getTree().repaint();// JTree } } else if ("addSongInfo".equals(btnName)) { 乐乐中歌曲乐型message = ""; } if ("delSongType".equals(btnName) && len == 1) { 乐除歌曲乐型// int answer = JOptionPane.showConfirmDialog(playerFrame, 确定要乐除,,,确框乐乐"", "", JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { DefaultMutableTreeNode delNode = (DefaultMutableTreeNode) path .getLastPathComponent(); String tempTypeId = delNode.toString().split(":")[0]; int typeId = Integer.valueOf(tempTypeId); /* 乐除歌曲乐型包括乐除乐乐型下的所有歌曲乐除乐乐型 * : , */ infoDao.delSongInfoByTypeId(typeId); infoDao.delSongType(typeId); 从中移除乐除的乐型乐点// JTree playerFrame.getTreeModel().removeNodeFromParent(delNode); } } else if ("delSongType".equals(btnName)) { 乐乐中歌曲乐型message = ""; } if ("delSong".equals(btnName) && len == 2) { 乐除歌曲// int selected = JOptionPane.showConfirmDialog(playerFrame, 确乐要乐除歌曲,,确框乐乐"", "", JOptionPane.YES_NO_OPTION); if (selected == JOptionPane.YES_OPTION) { 从数据乐中乐除歌曲信息// infoDao.delSongInfo(songNode.toString()); 从中移除乐歌曲的乐点信息// JTree playerFrame.getTreeModel().removeNodeFromParent(songNode); 刷新playerFrame.getTree().repaint();// JTree } } else if ("delSong".equals(btnName)) { 乐乐中歌曲message = ""; } if (message != null) { 警告JOptionPane.showMessageDialog(playerFrame, message, "", JOptionPane.WARNING_MESSAGE); } } } public String getSelectedSongName() { return selectedSongName; } public void setSelectedSongName(String selectedSongName) { this.selectedSongName = selectedSongName;} } 7.PlayerDocumentListener.java package cn.xtu.catqq.control.playerlistener;/** 乐的乐候~乐入的文乐器~乐乐入乐的操作找框档听听框* */ import java.awt.Color; import java.awt.GridLayout; import java.util.List; import javax.swing.JButton; import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;import cn.xtu.catqq.model.player.SongInfoDao;import cn.xtu.catqq.model.player.impl.SongInfoDaoImpl;import cn.xtu.catqq.view.player.PlayerFrame;public class PlayerDocumentListener implements DocumentListener { private PlayerFrame playerFrame; private List btnList; private SongInfoDao infoDao = new SongInfoDaoImpl();public PlayerDocumentListener(PlayerFrame playerFrame) { super(); this.playerFrame = playerFrame; this.btnList = playerFrame.getBtnList();} public void changedUpdate(DocumentEvent arg0) { // TODO Auto-generated method stub } public void insertUpdate(DocumentEvent e) { String input = playerFrame.getTxtQuery().getText(); if (input != null && !"".equals(input)) { documentOperate(input); } } public void removeUpdate(DocumentEvent e) { String input = playerFrame.getTxtQuery().getText(); if (input != null && !"".equals(input)) { documentOperate(input); } else { playerFrame.getQueryScrollPanel().setVisible(false); } } private void documentOperate(String input) { List result = infoDao.findSongName("%" + input + "%"); int size = result.size(); if (size != 0) { playerFrame.getQueryPanel().removeAll(); GridLayout mgr = null; if (size < 3) { mgr = new GridLayout(3, 1); } else { mgr = new GridLayout(size, 1); } playerFrame.getQueryPanel().setLayout(mgr); for (int i = 0; i < size; i++) { for (Object a : result.get(i)) { JButton btn = new JButton(a.toString()); btnList.add(btn); btn.setBackground(Color.WHITE); playerFrame.getQueryPanel().add(btn); } } registerListener(); playerFrame.getQueryScrollPanel().setVisible(true); } else { playerFrame.getQueryScrollPanel().setVisible(false); } } 注乐乐器册听// private void registerListener() { PlayerMouseListener mouseLis = playerFrame.getPmLis(); int len = btnList.size(); if (len > 0) { for (int i = 0; i < len; i++) { btnList.get(i).addMouseListener(mouseLis); } } } } 8.AddSongInfoActionListener.java package cn.xtu.catqq.control.playerlistener;/** 添加歌曲信息乐中按乐乐乐器会框听* */ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import cn.xtu.catqq.common.UniqueException;import cn.xtu.catqq.model.player.SongInfoDao;import cn.xtu.catqq.model.player.impl.SongInfoDaoImpl;import cn.xtu.catqq.view.player.AddSongInfoDialog;import cn.xtu.catqq.vo.SongInfo; public class AddSongInfoActionListener implements ActionListener { private AddSongInfoDialog addDialog; 以添加歌曲信息乐乐的乐造函乐会框参数构数使得在乐建乐乐器乐就乐得乐乐乐乐象的引用听会框// , public AddSongInfoActionListener(AddSongInfoDialog addDialog) {super(); this.addDialog = addDialog; } public void actionPerformed(ActionEvent e) { String btnName = e.getActionCommand(); if ("confirm".equals(btnName)) { /* 确乐提交添加歌曲信息 乐得乐中文本乐中的信息会框框 * , */ String songName = addDialog.getTxtSongName().getText();String songer = addDialog.getTxtSonger().getText();String ms = addDialog.getTxtMs().getText();String songType = addDialog.getBoxSongType().getSelectedItem() .toString().split(":")[0]; String typeName = addDialog.getBoxSongType().getSelectedItem() .toString().split(":")[1]; String songLoc = addDialog.getTxtSongLoc().getText(); 用存乐警告的信息来String mess = null;// if (songName == null || "".equals(songName)) { 歌曲名乐空mess = ""; } else { int songTypeId = Integer.valueOf(songType); SongInfo songInfo = new SongInfo(songName, songer, ms, songTypeId, songLoc); SongInfoDao infoDao = new SongInfoDaoImpl(); try { 往据乐中添加歌曲信息数infoDao.addSongInfo(songInfo);// /* 将歌曲信息添加到中方便乐的乐乐用乐乐乐得到乐会框 * List,List */ List songRow = addDialog.getSongInfo(); songRow.add(songName); songRow.add(ms); songRow.add(typeName); songRow.add(songLoc); addDialog.setSongInfo(songRow); 添加成功乐乐乐乐会框addDialog.dispose();// , } catch (UniqueException e1) { 歌曲名已存在JOptionPane.showMessageDialog(addDialog, ""); } } 警告消息不乐空乐乐出警告提示框// , if (mess != null) { 警告JOptionPane.showMessageDialog(addDialog, mess, "", JOptionPane.WARNING_MESSAGE); } } else if ("cancel".equals(btnName)) { 取消添加并将会框框乐的文本乐乐置成空// , 确定取消乐,int answer = JOptionPane.showConfirmDialog(addDialog, "", 确框定"", JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { addDialog.getTxtSongName().setText(""); addDialog.getTxtSonger().setText(""); addDialog.getTxtMs().setText(""); } } else { 乐乐文件乐文件位置找默乐是乐示所有文件// ,, JFileChooser chooser = new JFileChooser(); int returnVal = chooser.showOpenDialog(addDialog.getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { String realPath = chooser.getCurrentDirectory() .getAbsolutePath() + "\\" + chooser.getSelectedFile().getName(); addDialog.getTxtSongLoc().setText(realPath); } } } } 9.AddSongTypeActionListener.java package cn.xtu.catqq.control.playerlistener;/** 添加歌曲乐型乐的按乐乐乐器会框听* */ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JOptionPane; import javax.swing.tree.DefaultMutableTreeNode;import cn.xtu.catqq.common.UniqueException;import cn.xtu.catqq.model.player.SongInfoDao;import cn.xtu.catqq.model.player.impl.SongInfoDaoImpl; import cn.xtu.catqq.view.player.AddSongInfoTypeDialog;import cn.xtu.catqq.view.player.PlayerFrame; public class AddSongTypeActionListener implements ActionListener {private AddSongInfoTypeDialog dialog; /* 以添加歌曲乐型乐乐造函的以乐得乐乐乐乐象的引用会框构数参数会框 * */ public AddSongTypeActionListener(AddSongInfoTypeDialog dialog) { super(); this.dialog = dialog; } public void actionPerformed(ActionEvent e) { String btnName = e.getActionCommand(); if ("add".equals(btnName)) { 添加歌曲乐型// 乐得乐中的乐型乐乐会框号String tempTypeId = dialog.getTxtTypeId().getText();// 乐得乐乐中的乐型会框String typeName = dialog.getTxtTypeName().getText();// 名称 String message = null; if (tempTypeId == null || "".equals(tempTypeId)) { 乐型乐乐空号message = ""; } else if (typeName == null || "".equals(typeName)) { 乐型名乐空称message = ""; } else { int typeId = Integer.valueOf(tempTypeId); Object[] params = new Object[] { typeId, typeName }; SongInfoDao dao = new SongInfoDaoImpl(); try { dao.addSongType(params); 用建一乐点名, 乐型乐来构个StringBuffer sb = new StringBuffer();// 号乐型名: sb.append(tempTypeId); sb.append(":"); sb.append(typeName); PlayerFrame frame = dialog.getPlayerFrame(); 乐得根乐点// DefaultMutableTreeNode root = (DefaultMutableTreeNode) frame .getTreeModel().getRoot(); 以建好的乐点名建一乐点构构个// DefaultMutableTreeNode typeNode = new DefaultMutableTreeNode( sb.toString()); 将乐点添加到根乐点下// frame.getTreeModel().insertNodeInto(typeNode, root, root.getChildCount()); 乐乐乐乐会框dialog.dispose();// } catch (UniqueException e1) { 乐型乐已存在号JOptionPane.showMessageDialog(dialog, ""); } } 如果歌曲乐型乐或乐型名乐空~乐出警告消息号称框// if (message != null) { 警告JOptionPane.showMessageDialog(dialog, message, "", JOptionPane.WARNING_MESSAGE); } } else { 乐除歌曲乐型// 确定要取消乐,int selected = JOptionPane.showConfirmDialog(dialog, "", 确框乐乐"", JOptionPane.YES_NO_OPTION); if (selected == JOptionPane.YES_OPTION) { dialog.dispose(); } } } } 10.DBConnection.java package cn.xtu.catqq.common; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class DBConnection { static { try { Class.forName("oracle.jdbc.driver.OracleDriver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } } public static Connection openConnection() { Connection conn = null; try { conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORACLE", "scott", "tiger"); } catch (SQLException e) { e.printStackTrace(); } return conn; } public static void closeConnection(Connection conn, Statement st, ResultSet rs) { if(rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if(st != null) { try { st.close(); } catch (SQLException e) { e.printStackTrace(); } } if(conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } } 11.JDBCHelper.java package cn.xtu.catqq.common;import java.sql.Connection;import java.sql.Date; import java.sql.PreparedStatement;import java.sql.ResultSet; import java.sql.SQLException; import java.sql.ResultSetMetaData;import java.sql.Types; import java.util.ArrayList; import java.util.List; public class JDBCHelper { /** 乐行增乐改操作 * ,, 要乐行的乐句 * @param sql:sql 乐句中需要乐置的乐量乐 * @param params:sql 乐型名歌曲名乐惟一自定乐抛出常异有乐用者乐理常异 * @throws UniqueException:,,, */ public static void executeSQL(String sql, Object[] params) throws UniqueException { Connection conn = DBConnection.openConnection(); PreparedStatement pre = null; try { pre = conn.prepareStatement(sql); Object temp = null; for(int i = 0; i < params.length; i++) { temp = params[i]; if(temp instanceof Integer) { pre.setInt(i + 1, (Integer)temp); } else if(temp instanceof String) { pre.setString(i + 1, temp.toString()); } else if(temp instanceof Double) { pre.setDouble(i + 1, (Double)temp); } else if(temp instanceof Float) { pre.setFloat(i + 1, (Float)temp); } else if(temp instanceof Date) { pre.setDate(i + 1, (Date)temp); } } pre.execute(); } catch (SQLException e) { if(e.getErrorCode() == 1){ throw new UniqueException(e.getMessage()); } e.printStackTrace(); }finally{ DBConnection.closeConnection(conn, pre, null); } } /** 乐行乐乐的方法 * , 要乐行的 乐句 * @param sql:sql 乐乐乐句所要乐置的乐 * @param params: 返回一个乐果集 * @return:list */ public static List executeQuery(String sql, Object[] params) { Connection conn = DBConnection.openConnection();PreparedStatement pre = null; ResultSet rs = null; List result = new ArrayList(); try { pre = conn.prepareStatement(sql); Object temp = null; if(params != null) { for(int i = 0; i < params.length; i++) { temp = params[i]; if(temp instanceof Integer) { pre.setInt(i + 1, (Integer)temp); } else if(temp instanceof String) { pre.setString(i + 1, temp.toString()); } else if(temp instanceof Double) { pre.setDouble(i + 1, (Double)temp); } else if(temp instanceof Float) { pre.setFloat(i + 1, (Float)temp); } else if(temp instanceof Date) { pre.setDate(i + 1, (Date)temp); } } } rs = pre.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); Object[] columns = null; while(rs.next()) { 使用乐乐乐columns = new Object[rsmd.getColumnCount()];//ResultSet 果集的乐字段乐置据乐度数来数 for(int i = 0; i < columns.length; i++) { 乐取字段乐型int columnType = rsmd.getColumnType(i+1);// if(columnType == Types.INTEGER) { columns[i] = rs.getInt(i+1); } else if(columnType == Types.VARCHAR) { columns[i] = rs.getString(i + 1); } else if(columnType == Types.DATE) { columns[i] = rs.getDate(i + 1); } else if(columnType == Types.FLOAT) { columns[i] = rs.getFloat(i+1); } else { columns[i] = rs.getObject(i + 1); } } result.add(columns); } } catch (SQLException e) { e.printStackTrace(); }finally{ DBConnection.closeConnection(conn, pre, rs); } return result; } } 12.SQLContants.java package cn.xtu.catqq.common; public class SQLContants { public static final String QUERY_SONGTYPE="SELECT TYPEID,TYPENAME FROM SONGTYPE"; public static final String QUERY_SONGINFO="SELECT SONGID,SONGNAME,SONGER,SONGMAKER,SONGLOC,TYPENAME FROM SONGINFO,SONGTYPE WHERE SONGTYPE=TYPEID AND SONGNAME=?";public static final String QUERY_SONGNAMEBYSONGTYPE = "SELECT SONGNAME FROM SONGINFO WHERE SONGTYPE=?"; public static final String QUERY_SONGLOCBYSONGNAME="SELECT SONGLOC FROM SONGINFO WHERE SONGNAME=?"; public static final String ADDSONGINFO = "INSERT INTO SONGINFO VALUES(SEQ_SONG.NEXTVAL,?,?,?,?,?)"; public static final String DELSONGINFO = "DELETE FROM SONGINFO WHERE SONGNAME = ?"; public static final String ADDSONGTYPE = "INSERT INTO SONGTYPE VALUES(?,?)"; public static final String DELALLSONGBYTYPEID = "DELETE FROM SONGINFO WHERE SONGTYPE=?"; public static final String DELSONGTYPE = "DELETE FROM SONGTYPE WHERE TYPEID=?"; public static final String QUERY_SONGNAME = "SELECT SONGNAME FROM SONGINFO WHERE SONGNAME LIKE ?"; } 13.UniqueException.java package cn.xtu.catqq.common; /** 自定乐的常~乐反唯一乐束乐乐用异当* * @author Administrator */ public class UniqueException extends Exception {public UniqueException(String mess) { super(mess); } } 14.SongInfoDao.java package cn.xtu.catqq.model.player; import java.util.List; import cn.xtu.catqq.common.UniqueException; import cn.xtu.catqq.vo.SongInfo; public interface SongInfoDao { 乐乐歌曲乐型public List findSongList();// public List findSongName(int songType); 乐乐歌曲信息public List fingSongInfo(String songName);// 匹配歌曲名public List findSongName(String input);// 根据歌曲名乐乐歌曲路径public List findSongLoc(String songName);// 添加歌曲信息public void addSongInfo(SongInfo songInfo) throws UniqueException;// 乐除歌曲public void delSongInfo(String songName);// 添加歌曲乐型public void addSongType(Object[] params) throws UniqueException;// 根据歌曲乐型乐乐除乐乐型下得所有歌曲号public void delSongInfoByTypeId(int typeId);// 乐除歌曲乐型根据歌曲乐型乐号public void delSongType(int typeId);// } 15.SongInfoDaoImpl.java package cn.xtu.catqq.model.player.impl; import java.util.List; import cn.xtu.catqq.common.JDBCHelper; import cn.xtu.catqq.common.SQLContants; import cn.xtu.catqq.common.UniqueException;import cn.xtu.catqq.model.player.SongInfoDao;import cn.xtu.catqq.vo.SongInfo; public class SongInfoDaoImpl implements SongInfoDao {乐乐歌曲乐型// public List findSongList() { String sql = SQLContants.QUERY_SONGTYPE; return JDBCHelper.executeQuery(sql, null);} 乐乐歌曲信息// public List fingSongInfo(String songName) { String sql = SQLContants.QUERY_SONGINFO; return JDBCHelper.executeQuery(sql, new Object[] { songName }); } 乐乐歌曲名字// public List findSongName(int songType) { String sql = SQLContants.QUERY_SONGNAMEBYSONGTYPE; return JDBCHelper.executeQuery(sql, new Object[] { songType }); } 乐乐歌曲位置// public List findSongLoc(String songName) { String sql = SQLContants.QUERY_SONGLOCBYSONGNAME; return JDBCHelper.executeQuery(sql, new Object[] { songName });} 添加歌曲信息// public void addSongInfo(SongInfo songInfo) throws UniqueException { String sql = SQLContants.ADDSONGINFO; Object[] params = new Object[] { songInfo.getSongName(), songInfo.getSonger(), songInfo.getMs(), songInfo.getSongLoc(), songInfo.getSongType() }; JDBCHelper.executeSQL(sql, params); } 根据歌曲名乐除歌曲信息// public void delSongInfo(String songName) { String sql = SQLContants.DELSONGINFO; try { JDBCHelper.executeSQL(sql, new Object[] { songName }); } catch (UniqueException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 添加歌曲乐型// public void addSongType(Object[] params) throws UniqueException { String sql = SQLContants.ADDSONGTYPE; JDBCHelper.executeSQL(sql, params); } 根据歌曲乐型乐乐除乐乐型下所有歌曲号// public void delSongInfoByTypeId(int typeId) { String sql = SQLContants.DELALLSONGBYTYPEID; try { JDBCHelper.executeSQL(sql, new Object[] { typeId }); } catch (UniqueException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 乐除歌曲乐型// public void delSongType(int typeId) { String sql = SQLContants.DELSONGTYPE; try { JDBCHelper.executeSQL(sql, new Object[] { typeId }); } catch (UniqueException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public List findSongName(String input) { String sql = SQLContants.QUERY_SONGNAME; return JDBCHelper.executeQuery(sql, new Object[]{input});} }
/
本文档为【音乐播放器基本设计&#40;附源码&#41;】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
热门搜索

历史搜索

    清空历史搜索