public class SoundPlayerGUI extends JFrame

implements ChangeListener, ActionListener

{

private static final String VERSION = "Version 1.0";

private static final String AUDIO_DIR = "audio";

private JList fileList;
private JSlider slider;
private JLabel infoLabel; public static void main(String[] args)
{
SoundPlayerGUI gui = new SoundPlayerGUI();
} public SoundPlayerGUI()
{
super("SoundPlayer"); String[] audioFileNames = findFiles(AUDIO_DIR, null);
makeFrame(audioFileNames);
} private void play()
{
String filename = (String)fileList.getSelectedValue();
if(filename == null) { // nothing selected
return;
}
slider.setValue(0);
boolean successful = player.play(new File(AUDIO_DIR, filename)); } private void showInfo(String message)
{
infoLabel.setText(message);
} private void showAbout()
{
JOptionPane.showMessageDialog(this,
"SoundPlayer\n" + VERSION,
"About SoundPlayer",
JOptionPane.INFORMATION_MESSAGE);
} private String[] findFiles(String dirName, String suffix)
{
File dir = new File(dirName);
if(dir.isDirectory()) {
String[] allFiles = dir.list();
if(suffix == null) {
return allFiles;
}
else {
List<String> selected = new ArrayList<String>();
for(String filename : allFiles) {
if(filename.endsWith(suffix)) {
selected.add(filename);
}
}
return selected.toArray(new String[selected.size()]);
}
}
else {
System.out.println("");
return null;
}
} public void stateChanged(ChangeEvent evt)
{
player.seek(slider.getValue());
} public void actionPerformed(ActionEvent evt)
{
JComboBox cb = (JComboBox)evt.getSource();
String format = (String)cb.getSelectedItem();
if(format.equals("all formats")) {
format = null;
}
fileList.setListData(findFiles(AUDIO_DIR, format));
} private void makeFrame(String[] audioFiles)
{ JPanel contentPane = (JPanel)getContentPane();
contentPane.setBorder(new EmptyBorder(0, 0, 0, 0)); makeMenuBar(); contentPane.setLayout(new BorderLayout(0, 0));

contentPane.setBackground(new Color(0,0,0));

    JPanel leftPane = new JPanel();
{
leftPane.setLayout(new BorderLayout(188, 1)); String[] formats = { "all formats", ".wav", ".au", ".aif",".mp3" }; // Create the combo box.
JComboBox formatList = new JComboBox(formats);
formatList.addActionListener(this);
leftPane.add(formatList, BorderLayout.NORTH); // Create the scrolled list for file names
fileList = new JList(audioFiles);
fileList.setForeground(new Color(140,171,226));
fileList.setBackground(new Color(0,0,0));
fileList.setSelectionBackground(new Color(87,49,134));
fileList.setSelectionForeground(new Color(140,171,226));
JScrollPane scrollPane = new JScrollPane(fileList);
scrollPane.setColumnHeaderView(new JLabel("本地歌曲"));
leftPane.add(scrollPane, BorderLayout.CENTER);
JButton button = new JButton(new ImageIcon("play.jpg"));
button.setPressedIcon(new ImageIcon ("play1.jpg"));
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { play(); }
}); slider = new JSlider(0, 100, 0);
TitledBorder border = new TitledBorder("Seek");
border.setTitleColor(Color.white);
slider.setBorder(new CompoundBorder(new EmptyBorder(6, 10, 10, 10), border));
slider.addChangeListener(this);
slider.setBackground(Color.white);
slider.setMajorTickSpacing(25);
slider.setPaintTicks(true);
JPanel toolbar = new JPanel(); toolbar.setLayout(new GridLayout(2, 1)); toolbar.add(button);
toolbar.add(slider);
leftPane.add(toolbar,BorderLayout.NORTH); }
contentPane.add(leftPane, BorderLayout.WEST);
JPanel picPane=new JPanel();
{
JLabel pic=new JLabel(new ImageIcon("zhuomian.jpg"));
picPane.add(pic, BorderLayout.CENTER);
contentPane.add(picPane,BorderLayout.CENTER); } JPanel centerPane = new JPanel();
{
centerPane.setLayout(new BorderLayout(188, 8)); JLabel image = new JLabel(new ImageIcon("u=2786397887,625919022&fm=21&gp=0.jpg"));
centerPane.add(image, BorderLayout.NORTH);
centerPane.setBackground(Color.BLUE); infoLabel = new JLabel(new ImageIcon("zhi.jpg")); centerPane.add(infoLabel, BorderLayout.CENTER); }
contentPane.add(centerPane, BorderLayout.EAST); // Create the toolbar with the buttons pack(); // place this frame at the center of the screen and show
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setLocation(d.width/2 - getWidth()/2, d.height/2 - getHeight()/2);
setVisible(true);} private void makeMenuBar()
{
final int SHORTCUT_MASK =
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); JMenuBar menubar = new JMenuBar();
setJMenuBar(menubar); JMenu menu;
JMenuItem item; menu = new JMenu("File");
menubar.add(menu); item = new JMenuItem("Quit");
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, SHORTCUT_MASK));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { quit(); }
});
menu.add(item); ![](http://images2015.cnblogs.com/blog/906234/201605/906234-20160529200347225-1109277185.jpg) menu = new JMenu("Help");
menubar.add(menu); item = new JMenuItem("About SoundPlayer...");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { showAbout(); }
});
menu.add(item);
}

}

music player界面的更多相关文章

  1. 更改电脑名称后, Cnario无法播放画面和声音, 开机后停留在桌面, Cnario Player软件界面的停止按钮为蓝色可选状态

    症状描述 Cnario Player正常工作期间, 更改了电脑的Windows系统计算机名称(不是登录Windows的用户名), 重启后, 新计算机名生效. 此时Cnario自动启动, 但没有进入播放 ...

  2. 禁止Cnario Player启动后自动开始播放

    Cnario Player安装激活后, 默认开机后自动启动, 启动加载内容完成后进入10秒倒计时, 10秒后即开始播放关机前播放的内容. 如果不想让其自动开始播放, 可按照如下办法设置其不自动播放. ...

  3. 如何简单快速的修改Bootstrap

    Bootstrap并不是单单意味着HTML/CSS界面框架,更确切的说,它改变了整个游戏规则.这个囊括了应有尽有的代码框架使得许多应用和网站的设计开发变得简便许多,而且它将大量的HTML框架普及成了产 ...

  4. 最近玩Bootstrap , 一些小工具 记录在案。

    最近玩Bootstrap , 一些小工具 记录在案. 1 定制Bootstrap ,所见即所得的修改Bootstrap的各种变量,即时查看样式的变化. http://bootswatchr.com/ ...

  5. Unity iOS混合开发界面切换思路

    Unity iOS混合开发界面切换思路 最近有很多博友QQ 私信 或则 留言联系我,请教iOS和Unity界面之前相互切换的问题,源代码就不私下发你们了,界面跳转功能的代码我直接贴到下面好了,顺带说i ...

  6. Composer Player 属性设置

    /// <summary> /// 设置选中名称 /// </summary> /// <param name="name"></para ...

  7. 【Cocos2d-x for WP8 学习整理】(3)CCScrollView 实现捕鱼达人一样的场景选择界面

    UI 界面一般是游戏里比较独立的地方,因为游戏引擎一般都比较注意基础的功能封装,很少会关注UI,但是 UI 确是玩家第一眼看到的效果,因此能否实现一个美观的UI对于提升游戏的整体美观有着很大的帮助. ...

  8. VMware Player安装Debian系统

    尝试用虚拟机来安装Debian系统,感觉这样一来安装与卸载方便,二来也可以在Linux系统安装出现问题的情况下方便在host主机上查找解决方法,同时也避免了要重新设置分区来安装Linux系统(双系统的 ...

  9. 20套高品质的 Mobile & Web 界面 PSD 素材免费下载

    在这里,我们向大家呈现20个新鲜出炉的矢量的免费 PSD 素材.这些素材来自著名的设计社区——Dribbble,这个网站的用户不断发布各种精美的用户界面,图标和网站布局,以帮助激励他人.这些免费素材不 ...

随机推荐

  1. Mvc4学习笔记一(Ajax.ActionLink)

    <style type="text/css"> #left {width:200px; min-height:500px;border:1px solid #ccc;f ...

  2. tpch-kudu

    1.在impala里建立好文本表: create external table customer (C_CUSTKEY INT, C_NAME STRING, C_ADDRESS STRING, C_ ...

  3. Java JDBCI批量插入数据

    智能插入:将整批分批,每一千条提交一次,sql注入(安全,使用软解析,提高效率) sql注入攻击:简单例子 select * from table where name='"+un+&quo ...

  4. WC项目要求

    #include "stdio.h" #include "string.h" #include "stdlib.h" int charcal ...

  5. js对象的深度克隆

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 算法-MergeSort

    #include <iostream> #include <vector> #include <iterator> using namespace std; ; v ...

  7. ie7 用 clearfix 清除浮动时遇到的问题

    <!doctype html> <html> <head> <style> .fr{float:right;display:inline} li{bor ...

  8. maven项目管理利器

    一.maven介绍及环境搭建 maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建.报告和文档的软件项目管理工具. maven可以更有效的管理项目,也是一套功能强大的自动化管 ...

  9. Hadoop原理介绍

    Hadoop核心之HDFS 架构设计   老嗨 2015-09-18 16:55:00 浏览225 评论0 摘要: 概述:HDFS即Hadoop Distributed File System分布式文 ...

  10. html基础学习

    <html> 与 </html> 之间的文本描述网页 <body> 与 </body> 之间的文本是可见的页面内容 <h1> 与 </ ...