开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜