I wrote a very simple Java music player for a school project, and I wanted to add a little bit of sazza by implementing the volume slider. Basically, I read step by step how to do it, and it works, but there is one element that, frankly, I don’t understand, and that’s
(JSlider)event.getSource();
method. What I do not understand is what seems to be throwing. Why do I need to pass event.getSource () to JSlider? And how can I, since ChangeEvent and JSlider do not (in my opinion, at least) have a subclass / superclass relationship?
Here is the complete method:
public void stateChanged(ChangeEvent event)
{
JSlider source = (JSlider)event.getSource();
int volume = source.getValue();
setVolume(volume);
}
source
share