📄 appletsound.java
字号:
package appletsound;import java.awt.*;import java.awt.event.*;import java.applet.*;/** * <p>Title: Java声音演示程序</p> * <p>Description: 应用Applet API 处理声音</p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: 北京师范大学计算机系</p> * @author 孙一林 * @version 1.0 */public class AppletSound extends Applet { boolean isStandalone = false; String splay; private AudioClip sound; Button button1 = new Button(); Button button2 = new Button(); Button button3 = new Button(); //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construct the applet public AppletSound() { } //Initialize the applet public void init() { try { splay = this.getParameter("File", "spacemusic.au"); sound = getAudioClip( getDocumentBase(), splay ); } catch(Exception e) { e.printStackTrace(); } try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { button1.setLabel("播放"); button1.setBounds(new Rectangle(24, 35, 94, 41)); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); this.setLayout(null); button2.setBounds(new Rectangle(149, 35, 94, 41)); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button2_actionPerformed(e); } }); button2.setLabel("循环播放"); button3.setBounds(new Rectangle(279, 38, 94, 41)); button3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button3_actionPerformed(e); } }); button3.setLabel("停止播放"); this.add(button1, null); this.add(button2, null); this.add(button3, null); } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { String[][] pinfo = { {"File", "String", ""}, }; return pinfo; } void button1_actionPerformed(ActionEvent e) { sound.play(); } void button2_actionPerformed(ActionEvent e) { sound.loop(); } void button3_actionPerformed(ActionEvent e) { sound.stop(); } //Main method/* public static void main(String[] args) { AppletSound applet = new AppletSound(); applet.isStandalone = true; Frame frame; frame = new Frame() { protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } public synchronized void setTitle(String title) { super.setTitle(title); enableEvents(AWTEvent.WINDOW_EVENT_MASK); } }; frame.setTitle("Applet Frame"); frame.add(applet, BorderLayout.CENTER); applet.init(); applet.start(); frame.setSize(200,120); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2); frame.setVisible(true); }*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -