what JFrame objects support pitch change?

87 views Asked by At

I am trying to change the pitch of a wave file while mouse entering a JButton. the problem is the JButton object doesn't support the SAMPLE_RATE control. what can I do to change the pitch?

(FloatControl.Type.SAMPLE_RATE)
1

There are 1 answers

0
Hovercraft Full Of Eels On

JButtons of course will never support arbitrary functionality such as that -- they only can do and understand JButton related concepts, and this is as it should be. But all is not lost. You can give your JButton's ButtonModel a ChangeListener and then when the mouse is hovered over the button call the sample rate change on whatever object is controlling the sample rate. Note that in the ChangeListener you'll check the isRollover() method to check for hovering.

e.g.,

  button.getModel().addChangeListener(new ChangeListener() {

     @Override
     public void stateChanged(ChangeEvent cEvt) {
        ButtonModel model = (ButtonModel) cEvt.getSource();
        if (model.isRollover()) {
           // do something with pitch
        } else {
           // undo something with pitch
        }
     }
  });

Note, that you may need to do your pitch modification in a background thread off of Swing's event thread.