I've been writing a very basic musicplayer in Java for a school project, and I wanted to add a little sazz by implementing a volume slider. Basically, I read step by step how to do it, and it does work, but there is one element that I frankly don't understand, and that is the
(JSlider)event.getSource();
method. What I dont't understand is what seems to be casting. Why do I need to cast the event.getSource() to JSlider? And how can I even, since ChangeEvent and JSlider do not have a (to my understanding, at least) sub-class/superclass relationship?
Here is the method in full:
public void stateChanged(ChangeEvent event)
{
JSlider source = (JSlider)event.getSource();
int volume = source.getValue();
setVolume(volume);
}