20fb9e1d249a001b1a15912de8b02075

来自「《J2ME实用教程》 源文件下载 本书没有仅仅局限于J2ME单机游戏的开发」· 代码 · 共 37 行

TXT
37
字号
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
public class PlaySimpleTone extends MIDlet implements CommandListener {
	private Player mp;
	private Display display;
	private List list;
	private Command exitCommand = new Command("Exit", Command.EXIT, 2);
	private Command playCommand = new Command("Play", Command.ITEM, 1);
	public PlaySimpleTone() {
		display = Display.getDisplay(this);
		list = new List("音调例子", List.IMPLICIT);
	}
	public void startApp() {
		list.addCommand(exitCommand);
		list.addCommand(playCommand);
		list.setCommandListener(this);
		display.setCurrent(list);
	}
	public void commandAction(Command c, Displayable s) {
		if (c == exitCommand) {
			destroyApp(false);
			notifyDestroyed();
		}
		if (c == playCommand) {
			simpleTone();
		}
	}
	private void simpleTone() {
		try {
			Manager.playTone(ToneControl.C4, 100, 80);
		} catch (Exception ex) {
		}
	}
}

⌨️ 快捷键说明

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