📄 noisybutton.java
字号:
//file: NoisyButton.javaimport java.applet.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class NoisyButton extends JFrame { public NoisyButton(final AudioClip sound) { // set up the frame setTitle("NoisyButton"); addWindowListener(new WindowAdapter( ) { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(200, 200); setLocation(100, 100); // set up the button JButton button = new JButton("Woof!"); button.addActionListener(new ActionListener( ) { public void actionPerformed(ActionEvent e) { sound.play( ); } }); getContentPane( ).setBackground(Color.pink); getContentPane().setLayout(new GridBagLayout( )); getContentPane( ).add(button); setVisible(true); } public static void main(String[] args) throws Exception { java.io.File file = new java.io.File("bark.aiff"); AudioClip sound = Applet.newAudioClip(file.toURL( )); new NoisyButton(sound); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -