如何让我的程序从Ms Access数据库中获取歌曲? [英] How Do I Make My Program To Fetch A Song From Ms Access Database?

查看:73
本文介绍了如何让我的程序从Ms Access数据库中获取歌曲?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..

我想制作一个可以随机播放歌曲的简单音乐播放器。我想将歌曲的位置存储在MS Access数据库中,并希望我的程序从数据库中获取此位置并以随机顺序播放它们。有人可以帮我这个。以下是我迄今为止使用Java Media Framework完成的代码。

hi..
i want to make a simple music player which can shuffle songs. I want to store the location of the songs in MS Access database and want my program to fetch this location from the database and play them in random order. Can someone please help me with this. Following is the code i have done till now with Java Media Framework.


有必要安装jframe来运行这个程序。



import java.io 。*;

import java.awt。*;

import javax.swing。*;

import java.awt.event。*;

import javax.swing.filechooser。*;

import javax.swing.SwingUtilities;

import javax.media。*;

import java.io.File;

import java.net.URL;

import javax.media.Manager;

import javax.media.Player;

class audio extends JPanel实现ActionListener

{

JFrame框架;

JButton b1,b3,b2;

JPanel p,p2;

JFrame f1;

JMenuBar mbar;

JMenu m1,m2;

JMenuItem ofile,exitfile,aboutus;

JFileChooser fc;

private Player audioplayer = null;

private file file;

public audio()

{

f1 = new JFrame(Audio Player);

f1.setDefaultCloseOp eration(JFrame.EXIT_ON_CLOSE);

fc = new JFileChooser();

mbar = new JMenuBar();

mbar.setOpaque(true );

mbar.setBackground(新颜色(154,165,127));

m1 =新JMenu(文件);

m2 = new JMenu(帮助);

mbar.add(m1);

mbar.add(m2);

ofile = new JMenuItem(Open);

ofile.addActionListener(new playing());

exitfile = new JMenuItem(Exit);

exitfile.addActionListener(this);

aboutus = new JMenuItem(AboutUs);

aboutus.addActionListener(this);

m1.add(ofile);

m1.addSeparator();

m1.add(exitfile);

m2.add(aboutus) );

f1.setJMenuBar(mbar);

p = new JPanel();

p2 = new JPanel();

p.setLayout(null);

p.setBackground(Color.blue);

p.add(p2).setBounds(0,0,350,60 );

p2.setBackground(Color.darkGray);

f1.add(p);

b1 =新JButto n(播放);

b1.addActionListener(new playing());

// b2 =新JButton(shuffle);



b3 =新JButton(停止);

b3.setEnabled(false);

b3.addActionListener(this) ;

p2.add(b1);

p2.add(b3);

f1.setSize(350,110);

f1.setVisible(true);

}

public void actionPerformed(ActionEvent evt)

{

if(evt.getSource()== ofile)

{

int returnVal = fc.showOpenDialog(audio.this);

if(returnVal == JFileChooser.APPROVE_OPTION)

{

file = fc.getSelectedFile();

}

else

{

System.out.println(用户取消文件访问);

}

}

if(evt.getSource()== b3)

{

audioplayer.stop();

b1.setEnabled(true);

b3.setEnabled(false);

}

if(evt.getSource()== exitfile)

{

System.exit(0);

}

if(evt.getSource()== aboutus)

{

JFrame af1 =新JFrame(关于我们);

af1.setVisible(true);

af1.setSize(350,200);

af1.setLocation(300,300);

JPanel ap1 = new JPanel();

ap1.setBackground(Color.white);

af1.add(ap1);

JLabel l1 =新JLabel(,JLabel.CENTER);



ap1。添加(l1);

}

}

public void oplay()

{

fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

int result = fc.showOpenDialog(this);

if(result == JFileChooser.CANCEL_OPTION)

file = null;

else

file = fc.getSelectedFile();

}

public void cplay()

{

if(file == null)

return;

try

{

audioplayer = Manager.createRealizedPlayer(file.toURI()。toURL());

audioplayer.start();
}

catch(例外xe)

{

JOptionPane.showMessageDialog(框架,无效的文件类型.. ,加载页面时出错,JOptionPane.ERROR_MESSAGE);

}

}

公共类播放实现ActionListener

$

public void actionPerformed(ActionEvent e)

{

oplay();

cplay() ;

b1.setEnabled(false);

b3.setEnabled(true);

}

}

public static void main(String args [])

{

audio me = new audio();

}

}

it is necessary to install jframe to run this program.

import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.filechooser.*;
import javax.swing.SwingUtilities;
import javax.media.*;
import java.io.File;
import java.net.URL;
import javax.media.Manager;
import javax.media.Player;
class audio extends JPanel implements ActionListener
{
JFrame frame;
JButton b1,b3,b2;
JPanel p,p2;
JFrame f1;
JMenuBar mbar;
JMenu m1,m2;
JMenuItem ofile,exitfile,aboutus;
JFileChooser fc;
private Player audioplayer=null;
private File file;
public audio()
{
f1=new JFrame("Audio Player");
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fc=new JFileChooser();
mbar=new JMenuBar();
mbar.setOpaque(true);
mbar.setBackground(new Color(154, 165, 127));
m1=new JMenu("File");
m2=new JMenu("Help");
mbar.add(m1);
mbar.add(m2);
ofile=new JMenuItem("Open");
ofile.addActionListener(new playing());
exitfile=new JMenuItem("Exit");
exitfile.addActionListener(this);
aboutus=new JMenuItem("AboutUs");
aboutus.addActionListener(this);
m1.add(ofile);
m1.addSeparator();
m1.add(exitfile);
m2.add(aboutus);
f1.setJMenuBar(mbar);
p=new JPanel();
p2=new JPanel();
p.setLayout(null);
p.setBackground(Color.blue);
p.add(p2).setBounds(0,0,350,60);
p2.setBackground(Color.darkGray);
f1.add(p);
b1=new JButton("Play");
b1.addActionListener(new playing());
//b2=new JButton("shuffle");

b3=new JButton("Stop");
b3.setEnabled(false);
b3.addActionListener(this);
p2.add(b1);
p2.add(b3);
f1.setSize(350,110);
f1.setVisible(true);
}
public void actionPerformed(ActionEvent evt)
{
if(evt.getSource()==ofile)
{
int returnVal=fc.showOpenDialog(audio.this);
if(returnVal==JFileChooser.APPROVE_OPTION)
{
file=fc.getSelectedFile();
}
else
{
System.out.println("File Access Canceled by user");
}
}
if(evt.getSource()==b3)
{
audioplayer.stop();
b1.setEnabled(true);
b3.setEnabled(false);
}
if(evt.getSource()==exitfile)
{
System.exit(0);
}
if(evt.getSource()==aboutus)
{
JFrame af1=new JFrame("About Us");
af1.setVisible(true);
af1.setSize(350,200);
af1.setLocation(300,300);
JPanel ap1=new JPanel();
ap1.setBackground(Color.white);
af1.add(ap1);
JLabel l1=new JLabel("",JLabel.CENTER);

ap1.add(l1);
}
}
public void oplay()
{
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result=fc.showOpenDialog(this);
if(result==JFileChooser.CANCEL_OPTION)
file=null;
else
file=fc.getSelectedFile();
}
public void cplay()
{
if(file==null)
return;
try
{
audioplayer = Manager.createRealizedPlayer(file.toURI().toURL());
audioplayer.start();
}
catch(Exception xe)
{
JOptionPane.showMessageDialog(frame,"Invalid Files Types..","Error loading page",JOptionPane.ERROR_MESSAGE);
}
}
public class playing implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
oplay();
cplay();
b1.setEnabled(false);
b3.setEnabled(true);
}
}
public static void main(String args[])
{
audio me = new audio();
}
}

推荐答案

这篇关于如何让我的程序从Ms Access数据库中获取歌曲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆