📄 playtonedemo.java
字号:
/*
* PlayToneDemo.java
*
* Created on 2005年5月1日, 下午11:51
*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
*
* @author Liu Bin
* @version
*/
public class PlayToneDemo extends MIDlet implements CommandListener {
private Display display;
Form form = new Form("音调播放演示");
TextField tfNote = new TextField("请输入音调(0-127)", "49", 3,
TextField.NUMERIC);
TextField tfDuration = new TextField("请输入持续时间(毫秒)", "1000", 10,
TextField.NUMERIC);
Gauge gagVol = new Gauge("请选择音量", true, 100, 80);
//命令按钮
private Command cmdPlay = new Command("播放", Command.OK, 1);
private Command cmdExit = new Command("退出", Command.STOP, 1);
public PlayToneDemo() {
gagVol.setLayout(Item.LAYOUT_EXPAND);
form.append(tfNote);
form.append(tfDuration);
form.append(gagVol);
form.addCommand(cmdPlay);
form.addCommand(cmdExit);
form.setCommandListener(this);
}
public void startApp() {
display = Display.getDisplay(this);
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
/**
* 命令按钮事件
*/
public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if (label.equals("退出")) {
this.notifyDestroyed();
}
if (label.equals("播放")) {
//获得音调
int note = Integer.parseInt(this.tfNote.getString());
if ((note>=0) && (note<=127)) {
//在音调值有效时继续处理
int duration = Integer.parseInt(this.tfDuration.getString());
int vol = this.gagVol.getValue();
try {
javax.microedition.media.Manager.playTone(note, duration, vol);
} catch (Exception e) {
System.out.println("播放声调发生异常:" + e.toString());
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -