Java Reference
In-Depth Information
LISTING 11.12
continued
playButton.addActionListener (
new
ButtonListener());
current =
null
;
}
//*****************************************************************
// Represents the action listener for the combo box.
//*****************************************************************
private class
ComboListener
implements
ActionListener
{
//--------------------------------------------------------------
// Stops playing the current selection (if any) and resets
// the current selection to the one chosen.
//--------------------------------------------------------------
public void
actionPerformed (ActionEvent event)
{
if
(current !=
null
)
current.stop();
current = music[musicCombo.getSelectedIndex()];
}
}
//*****************************************************************
// Represents the action listener for both control buttons.
//*****************************************************************
private class
ButtonListener
implements
ActionListener
{
//--------------------------------------------------------------
// Stops the current selection (if any) in either case. If
// the play button was pressed, start playing it again.
//--------------------------------------------------------------
public void
actionPerformed (ActionEvent event)
{
if
(current !=
null
)
current.stop();
if
(event.getSource() == playButton)
if
(current !=
null
)
current.play();
}
}
Search WWH ::
Custom Search