/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package windowtest; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.applet.AudioClip; import java.net.URL; /** * * @author jcmt */ public class JukeBoxControls extends JPanel { private JComboBox musicCombo; private JButton stopButton, playButton; private AudioClip[] music; private AudioClip current; public JukeBoxControls() { URL url1, url2; url1 = url2 = null; try { url1 = new URL("file","localhost", "westernBeat.wav"); url2 = new URL("file","localhost", "classical.wav"); } catch (Exception exception) {} music = new AudioClip[3]; music[0] = null; // "Make a selection" music[1] = JApplet.newAudioClip(url1); music[2] = JApplet.newAudioClip(url2); String[] musicName = {"Make a selection...", "Western Beat", "Classical"}; musicCombo = new JComboBox(musicName); musicCombo.setBackground(Color.cyan); setSize(250,300); add(musicCombo); musicCombo.addActionListener(new ComboListener()); playButton = new JButton("Play", new ImageIcon("play.gif")); add(playButton); playButton.addActionListener(new ButtonListener()); } private class ComboListener implements ActionListener { public void actionPerformed(ActionEvent event) { if (current != null) current.stop(); 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(); } } }