playsound.java

来自「how to make a game using java.」· Java 代码 · 共 47 行

JAVA
47
字号
//PlaySound.java
//[Imperial Snowman Soft]

import java.awt.*;
import java.awt.event.*;
import java.applet.*;


public class PlaySound extends Applet implements ActionListener
{ 


	Button playbutton;
	Button stopbutton;
	AudioClip soundclip;


	public void init()

	//The init() method of an applet
	{
		super.init();
		playbutton = new Button("Play");
		playbutton.addActionListener(this); //Add to the ActionListener
		add(playbutton);
		stopbutton = new Button("Stop");
		stopbutton.addActionListener(this); //Add to the ActionListener
		add(stopbutton);
		soundclip = getAudioClip(getCodeBase(),"blitz.au");
	} 

	public void actionPerformed(ActionEvent event) //The event method
	{

		String cmd = event.getActionCommand(); //get the ActionCommand
		if (cmd.equals("Play"))
		{
			soundclip.loop();
		}
		else if (cmd.equals("Stop"))
		{
			soundclip.stop();
		}
	} 

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?