java课程设计源代码

上传人:aa****6 文档编号:37567312 上传时间:2018-04-18 格式:DOCX 页数:13 大小:20.19KB
返回 下载 相关 举报
java课程设计源代码_第1页
第1页 / 共13页
java课程设计源代码_第2页
第2页 / 共13页
java课程设计源代码_第3页
第3页 / 共13页
java课程设计源代码_第4页
第4页 / 共13页
java课程设计源代码_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《java课程设计源代码》由会员分享,可在线阅读,更多相关《java课程设计源代码(13页珍藏版)》请在金锄头文库上搜索。

1、package ui;import java.awt.EventQueue; /线程分发import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException;import org.jvnet.substance.SubstanceLookAndFeel;import musicPlayer.MusicPanel;public class Main public static void main(

2、String args) try / 设置观感 UIManager.setLookAndFeel(“org.jvnet.substance.skin.SubstanceBu sinessBlackSteelLookAndFeel“); / 设置水印 SubstanceLookAndFeel.setCurrentWatermark(“org.jvnet.substance.watermark.S ubstanceMangoLookAndFeel“); / 设置渐变渲染 SubstanceLookAndFeel.setCurrentGradientPainter(“org.jvnet.substa

3、nce.paint er.WaveGradientPainter“);JFrame.setDefaultLookAndFeelDecorated(true); / 窗体 JDialog.setDefaultLookAndFeelDecorated(true); /对话框 catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) e.printStackTrace(); /e为对象引用的名称/在命令行打印异常信息在程序中

4、出错的位置及原因 EventQueue.invokeLater() - /调用完毕,自动销毁 (因为是一个匿名类) new MusicPanel(); );package musicPlayer;import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.util.Vector;import javax.swing.JButton; imp

5、ort javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.DefaultTableModel;import player.Player;public class MusicPanel extends JFram

6、e /* */ private static final long serialVersionUID = 1L; private JButton add, playbtn, stopbtn, deletebtn, deleteAllbtn, upbtn, downbtn; private JTable table; / 歌曲信息表 private Player player;public MusicPanel() super(“音乐播放器“); initCompont(); setVisible(true); /* 初始化界面* */ private void initCompont() /

7、各个按钮赋初始值 add = new JButton(“导入“); playbtn = new JButton(“试听“); stopbtn = new JButton(“停止“); deletebtn = new JButton(“单曲删除“); deleteAllbtn = new JButton(“全部删除“); upbtn = new JButton(“上移“); downbtn = new JButton(“下移“);/ 导入按钮点击设置 add.addActionListener(new ActionListener() public void actionPerformed(Ac

8、tionEvent e) addFile(); );/ 试听按钮点击设置 playbtn.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) if (player != null) player.stop(); player = null; int rowNum = table.getSelectedRow(); / 选中 行时返回-1 if (rowNum != -1) / getValueAt获取表格内容 player = new Player(String) table.get

9、ValueAt(rowNum, 1) + “, (String) table.getValueAt(rowNum, 0); System.out.printf(String) table.getValueAt(rowNum, 1) + “, (String) table.getValueAt(rowNum, 0); player.play(); );/ 停止按钮点击设置 stopbtn.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) if (player != null) pla

10、yer.stop(); player = null; );/ 单曲删除按钮点击设置 deletebtn.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) int rowNum = table.getSelectedRow(); if (rowNum != -1) (DefaultTableModel) table.getModel().removeRow(rowNum); ); / 删除全部按钮点击设置 deleteAllbtn.addActionListener(new Acti

11、onListener() public void actionPerformed(ActionEvent e) for (int i = table.getRowCount() - 1; i = 0; i-) (DefaultTableModel) table.getModel().removeRow(i); ); downbtn.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) int n = table.getSelectedRow() + 1; if (n = 0) tabl

12、e.setRowSelectionInterval(n, n); ); / 添加各个按钮 JPanel btnPanel = new JPanel(); btnPanel.add(add); btnPanel.add(playbtn); btnPanel.add(stopbtn); btnPanel.add(deletebtn);btnPanel.add(deleteAllbtn); btnPanel.add(upbtn); btnPanel.add(downbtn); this.setLayout(new BorderLayout(); this.add(btnPanel, BorderLa

13、yout.NORTH);Vector tableContent = new Vector(); Vector columnName = new Vector();columnName.add(“歌曲名称“); columnName.add(“存放路径“);/ 设置table table = new JTable(tableContent, columnName); table.setSelectionBackground(Color.blue); table.setSelectionForeground(Color.LIGHT_GRAY);this.add(new JScrollPane(ta

14、ble), BorderLayout.CENTER); this.setSize(600, 210); /* 添加文件* */private void addFile() JFileChooser fc = new JFileChooser(); / 设置选入文件类型 FileNameExtensionFilter filter = new FileNameExtensionFilter( “mp3 or wav file“, “mp3“, “wav“, “MP3“, “WAV“); fc.setFileFilter(filter); fc.setFileSelectionMode(JFile

15、Chooser.FILES_ONLY); / 设置只选文件 fc.setMultiSelectionEnabled(true); / 设置 选择多个文件int intRetVal = fc.showDialog(this, “打开“); / 获取文件并添加到table if (intRetVal = JFileChooser.APPROVE_OPTION) File file = fc.getSelectedFiles(); String name; for (File var : file) name = var.getName().toLowerCase(); if (name.endsW

16、ith(“.mp3“) | name.endsWith(“.wav“) this.addMusicItem(var.getName(), var.getParentFile() .getAbsolutePath(); /* table的行中添加音乐文件名称name,音乐文件路径path*/ private void addMusicItem(String name, String path) Vector rowData = new Vector(); rowData.add(name); rowData.add(path); DefaultTableModel tabMod = (Defau

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 毕业论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号