Search code examples
javaswingjslider

How to differentiate stateChanged(ChangeEvent e) with multiple JSlider in the same class


I'm trying to write a program that has multiple JSliders in the same class, for JSliders to perform the actions I want it too, I need to define the actions inside stateChanged(ChangeEvent e), but how do I differentiate the actions of different sliders inside the same method?


Solution

  • but how do I differentiate the actions of different sliders inside the same method?

    Same as for any similar Swing event -- get the source by calling getSource() on the XxxxEvent object, here I believe that it's a ChangeEvent, and with that source you can check which JSlider initiated the event.