import javax.swing.*;
public class JukeBox {
    public static void main(String args[]){
        JFrame frame = new JFrame("Java Audio Player");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JukeBoxControls controlPanel = new JukeBoxControls();        frame.getContentPane().add(controlPanel);
        frame.pack();
        frame.setVisible(true);
    }
}import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.AudioClip;
import java.net.URL;public class JukeBoxControls extends JPanel{
    private JComboBox musicCombo;
    private JButton stopButton, playButton;
    private AudioClip [] music;
    private AudioClip current;    public JukeBoxControls(){
        URL url1,url2,url3,url4,url5,url6;
        url1 = url2 = url3 = url4 = url5 = url6 = null;
        try{
            url1 = new URL("file", "localhost", "1.wma");
            url2 = new URL("file", "localhost", "2.wma");
            url3 = new URL("file", "localhost", "3.wma");
            url4 = new URL("file", "localhost", "4.wma");
            url5 = new URL("file", "localhost", "5.wma");
            url6 = new URL("file", "localhost", "6.wma");        }catch (Exception e){}        music = new AudioClip[7];
        music[0] = null;
        music[1] = JApplet.newAudioClip(url1);
        music[2] = JApplet.newAudioClip(url2);
        music[3] = JApplet.newAudioClip(url3);
        music[4] = JApplet.newAudioClip(url4);
        music[5] = JApplet.newAudioClip(url5);
        music[6] = JApplet.newAudioClip(url6);        JLabel titleLabel = new JLabel("Java Juke Box");
        titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT);        String[] musicNames = {"make a selection","one","two","three","four","five","six"};
        musicCombo = new JComboBox(musicNames);
        musicCombo.setAlignmentX(Component.CENTER_ALIGNMENT);        playButton = new JButton("Play",new ImageIcon("play.jpg"));
        playButton.setBackground(Color.white);
        playButton.setMnemonic('P');        stopButton = new JButton("Stop", new ImageIcon("stop.jpg"));
        stopButton.setBackground(Color.white);
        stopButton.setMnemonic('S');        JPanel buttons = new JPanel();
        buttons.setLayout(new BoxLayout (buttons,BoxLayout.X_AXIS));
        buttons.add(playButton);
        buttons.add(Box.createRigidArea(new Dimension(5,0)));
        buttons.add(stopButton);
        buttons.setBackground(Color.cyan);        setPreferredSize(new Dimension(300,100));
        setBackground(Color.cyan);
        setLayout(new BoxLayout (this, BoxLayout.Y_AXIS));
        add(Box.createRigidArea(new Dimension(0,5)));
        add(musicCombo);
        add(Box.createRigidArea(new Dimension(0,5)));
        add(buttons);
        add(Box.createRigidArea(new Dimension(0,5)));
        musicCombo.addActionListener(new ComboListener());
        stopButton.addActionListener(new ButtonListener());
        playButton.addActionListener(new ButtonListener());
    }    private class ComboListener implements ActionListener{
        public void actionPerformed(ActionEvent evnet){
            if(current != null)
                current.play();            current = music[musicCombo.getSelectedIndex()];
        }
    }    private class ButtonListener implements ActionListener{
        public void actionPerformed(ActionEvent event){
            if(current != null)
                current.stop();            if(event.getSource() == playButton)
                if(current != null)
                    current.play();
        }
    }}