📄 volumecontroldemo.java
字号:
//import java.io.IOException;
//import java.io.InputStream;
//
import javax.microedition.lcdui.*;
//import javax.microedition.media.*;
//import javax.microedition.media.control.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class VolumeControlDemo extends MIDlet
implements CommandListener {
private Display display;
private Command exitCommand;
private Command playCommand;
private Command stopCommand;
private Command pauseCommand;
private Form f;
private MusicCanvas musicCanvas;
public VolumeControlDemo() {
// TODO Auto-generated constructor stub
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT, 2);
playCommand = new Command("Play", Command.SCREEN, 2);
stopCommand = new Command("Stop", Command.SCREEN, 2);
pauseCommand = new Command("pause", Command.SCREEN, 2);
f = new Form("正在播放");
musicCanvas = new MusicCanvas();
if (musicCanvas != null) {
musicCanvas.addCommand(exitCommand);
musicCanvas.addCommand(playCommand);
musicCanvas.addCommand(stopCommand);
musicCanvas.addCommand(pauseCommand);
musicCanvas.setCommandListener(this);
}
}
protected void destroyApp(boolean arg0)
throws MIDletStateChangeException {
// TODO Auto-generated method stub
musicCanvas.close();
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
if (musicCanvas != null) {
display.setCurrent(musicCanvas);
musicCanvas.start();
}
}
public void commandAction(Command c, Displayable s) {
/*if语句也可以用以下的*/
// String m = c.getLabel();
// if (m.equals("Exit")) {
// try {
// destroyApp(true);
// } catch (MIDletStateChangeException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// notifyDestroyed();
// }
if (c == exitCommand) {
musicCanvas.close();
try {
destroyApp(true);
} catch (MIDletStateChangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
notifyDestroyed();
} else if (c == playCommand) {
musicCanvas.playsong();
f.setTicker(new Ticker("播放中"));
display.setCurrent(musicCanvas);
} else if (c == stopCommand) {
musicCanvas.close();
display.setCurrent(musicCanvas);
} else if (c == pauseCommand) {
musicCanvas.pause();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -