make a JButton action audible with a "click" sound
Is there a built-in feature to make a Swing JButton audible. I am interested in a cl开发者_StackOverflow中文版ick or beep sound. I know I can invoke noise making code in the event handler, but I am specifically inquiring about any built-in capability that only needs to be enabled.
No, Swing is only about gui. I think there isn't any built-in feature like that. You should add an action listener to your JButton and handle that feature inside actionPerformed method.
JButton b = new JButton();
b.addActionListener(listener); //where listener implements ActionListener
//inside your listener
public void actionPerformed(ActionEvent e){
//play your sound
}
For what concern audio playback you can have a look at java sound api.
精彩评论