Java Reference
In-Depth Information
LISTING 11.12
continued
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);
// Create the list of strings for the combo box options
String[] musicNames = {"Make A Selection...", "Western Beat",
"Classical Melody", "Jeopardy Theme", "New Age Rythm",
"Eighties Jam", "Alfred Hitchcock's Theme"};
musicCombo =
new
JComboBox (musicNames);
musicCombo.setAlignmentX (Component.CENTER_ALIGNMENT);
// Set up the buttons
playButton =
new
JButton ("Play",
new
ImageIcon ("play.gif"));
playButton.setBackground (Color.white);
playButton.setMnemonic ('p');
stopButton =
new
JButton ("Stop",
new
ImageIcon ("stop.gif"));
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);
// Set up this panel
setPreferredSize (
new
Dimension (300, 100));
setBackground (Color.cyan);
setLayout (
new
BoxLayout (
this
, BoxLayout.Y_AXIS));
add (Box.createRigidArea (
new
Dimension(0,5)));
add (titleLabel);
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());
Search WWH ::
Custom Search