music player界面

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);

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界面的更多相关文章
- 更改电脑名称后, Cnario无法播放画面和声音, 开机后停留在桌面, Cnario Player软件界面的停止按钮为蓝色可选状态
症状描述 Cnario Player正常工作期间, 更改了电脑的Windows系统计算机名称(不是登录Windows的用户名), 重启后, 新计算机名生效. 此时Cnario自动启动, 但没有进入播放 ...
- 禁止Cnario Player启动后自动开始播放
Cnario Player安装激活后, 默认开机后自动启动, 启动加载内容完成后进入10秒倒计时, 10秒后即开始播放关机前播放的内容. 如果不想让其自动开始播放, 可按照如下办法设置其不自动播放. ...
- 如何简单快速的修改Bootstrap
Bootstrap并不是单单意味着HTML/CSS界面框架,更确切的说,它改变了整个游戏规则.这个囊括了应有尽有的代码框架使得许多应用和网站的设计开发变得简便许多,而且它将大量的HTML框架普及成了产 ...
- 最近玩Bootstrap , 一些小工具 记录在案。
最近玩Bootstrap , 一些小工具 记录在案. 1 定制Bootstrap ,所见即所得的修改Bootstrap的各种变量,即时查看样式的变化. http://bootswatchr.com/ ...
- Unity iOS混合开发界面切换思路
Unity iOS混合开发界面切换思路 最近有很多博友QQ 私信 或则 留言联系我,请教iOS和Unity界面之前相互切换的问题,源代码就不私下发你们了,界面跳转功能的代码我直接贴到下面好了,顺带说i ...
- Composer Player 属性设置
/// <summary> /// 设置选中名称 /// </summary> /// <param name="name"></para ...
- 【Cocos2d-x for WP8 学习整理】(3)CCScrollView 实现捕鱼达人一样的场景选择界面
UI 界面一般是游戏里比较独立的地方,因为游戏引擎一般都比较注意基础的功能封装,很少会关注UI,但是 UI 确是玩家第一眼看到的效果,因此能否实现一个美观的UI对于提升游戏的整体美观有着很大的帮助. ...
- VMware Player安装Debian系统
尝试用虚拟机来安装Debian系统,感觉这样一来安装与卸载方便,二来也可以在Linux系统安装出现问题的情况下方便在host主机上查找解决方法,同时也避免了要重新设置分区来安装Linux系统(双系统的 ...
- 20套高品质的 Mobile & Web 界面 PSD 素材免费下载
在这里,我们向大家呈现20个新鲜出炉的矢量的免费 PSD 素材.这些素材来自著名的设计社区——Dribbble,这个网站的用户不断发布各种精美的用户界面,图标和网站布局,以帮助激励他人.这些免费素材不 ...
随机推荐
- 腾讯云服务器centos 6.5(jdk+tomcat+vsftp)、腾讯mysql数据库 及 tomcat自启动 配置教程
1.腾讯云数据库配置 1.考虑到安全性问题,,平常不使用root用户登录,新增一个用户名neil,用来管理项目的数据库 a.首先登录root创建db_AA数据库 b.在root用户下,创建neil用户 ...
- MiniTwitter记住密码等功能实现
一.SharedPreferences的用法:(相关实现功能的只是了解) 由于SharedPreferences是一个接口,而且在这个接口里没有提供写入数据和读取数据的能力.但它是通过其Editor接 ...
- visual studio code 安装python扩展
Ctrl+P 调出控制台,在控制台里输入ext install python,点击第一个安装 如果出现: visual studio code connect ETIMEDOUT 191.238.17 ...
- VM virtuaBox异常关机启动不了的解决方案
事件回放 我的物理机是win7,上面装了一个VM virtualBox,用来装Centos,有天物理机非正常关闭,导致VM virtuaBox异常关机启动不了,如下: 确实找不到这个vm_liang. ...
- break into Ubuntu System
This morning, I got a spare machine from of of the labmates. The OS is ubuntu 12.04. I could not log ...
- CDS
very nice artical talk about mergechangelog and cleardataset Delta and Data http://www.cnblogs.com/y ...
- Unity 几种碰撞模式
1.OnControllerColliderHit 事件 (角色控制器使用) 2.Physics.Raycast 函数 3.OnTriggerEnter 事件 (碰撞物体使用,给碰撞物体添加碰撞器, ...
- nim也玩一行流,nim版的list comprehension
nim 是一门风格类似python的静态编译型语言,官方网站:http://nim-lang.org 如果你想折腾nim的编辑环境,可以用sublime text3 +插件nimlime,notepa ...
- 活用shape、selector和layer-list来打造自己想要的背景效果
活用shape.selector和layer-list来打造自己想要的背景效果 2016-04-27 13:52 281人阅读 评论(0) 收藏 举报 版权声明:本文为博主原创文章,未经博主允许不得转 ...
- JAVA vo pojo javabean dto区别
JavaBean 是一种JAVA语言写成的可重用组件.为写成JavaBean,类必须是具体的和公共的,并且具有无参数的构造器.JavaBean 通过提供符合一致性设计模式的公共方法将内部域暴露成员属性 ...