?? 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 + -