?? mainmidlet.java
字號:
package com.j2medev.chapter7;
import java.io.IOException;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.Player;
import javax.microedition.media.control.ToneControl;
public class MainMIDlet extends MIDlet implements CommandListener {
private Display display = null;
private List menu = null;
private PlayerUI canvas = null;
private Command exitCommand = new Command("Exit",Command.EXIT,1);
private Command playCommand = new Command("Play",Command.OK,2);
public static final String[] items = {"play tones","play wav","play video"};
public MainMIDlet(){
}
public void startApp() {
if(display == null){
display = Display.getDisplay(this);
menu = new List("player",List.IMPLICIT,items,null);
menu.addCommand(exitCommand);
menu.setSelectCommand(playCommand);
menu.setCommandListener(this);
}
display.setCurrent(menu);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
if(canvas != null){
canvas.stopPlayer();
canvas = null;
}
}
public List getMenu(){
return menu;
}
public void setCurrent(Displayable displayable){
if(display != null)
display.setCurrent(displayable);
}
public void commandAction(Command cmd,Displayable displayable){
if(cmd == exitCommand){
destroyApp(false);
notifyDestroyed();
}else if(cmd == playCommand || cmd == List.SELECT_COMMAND){
int i = menu.getSelectedIndex();
if(i == 0){
/* try{
Manager.playTone(60, 200, 90);
}catch(MediaException ex){
ex.printStackTrace();
}
*/
playToneSequence();
}else{
if(canvas == null){
canvas = new PlayerUI(this);
}
canvas.setType(i);
canvas.startPlayer();
display.setCurrent(canvas);
}
}
}
private void playToneSequence(){
byte tempo = 30;
byte d = 8;
byte C4 = ToneControl.C4;;
byte D4 = (byte)(C4 + 2);
byte E4 = (byte)(C4 + 4);
byte G4 = (byte)(C4 + 7);
byte rest = ToneControl.SILENCE;
byte[] mySequence = {
ToneControl.VERSION, 1,
ToneControl.TEMPO, tempo,
ToneControl.BLOCK_START, 0,
E4,d, D4,d, C4,d, E4,d,
E4,d, E4,d, E4,d, rest,d,
ToneControl.BLOCK_END, 0,
ToneControl.PLAY_BLOCK, 0,
D4,d, D4,d, D4,d, rest,d,
E4,d, G4,d, G4,d, rest,d,
ToneControl.PLAY_BLOCK, 0,
D4,d, D4,d, E4,d, D4,d, C4,d
};
try{
Player p = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
p.realize();
ToneControl c = (ToneControl)p.getControl("ToneControl");
c.setSequence(mySequence);
p.start();
} catch (IOException ioe) {
} catch (MediaException me) { }
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -