ToneMidlet01


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.*;

public class ToneMIDlet01 extends MIDlet implements CommandListener{

private Command exitCommand, playCommand;
private Form form;
private Gauge volumeGauge;
private Gauge durationGauge;
private Gauge toneGauge;
private Display display;
private int duration = 2; // seconds
private int volume = 100;
private int tone = ToneControl.C4;
private static int MAX_VOLUME = 100;
private static int MAX_TONE = 127;
private static int MAX_DURATION = 5;

public ToneMIDlet01() {
playCommand = new Command(“Play”, Command.OK, 1);
exitCommand = new Command(“Exit”, Command.EXIT, 1);
volumeGauge = new Gauge(“Volume”, true, MAX_VOLUME, volume);
toneGauge = new Gauge(“Tone”, true, MAX_TONE, tone);
durationGauge = new Gauge(“Duration”, true, MAX_DURATION, duration);
form = new Form(“Tone Player”);
form.addCommand(playCommand);
form.addCommand(exitCommand);
form.append(volumeGauge);
form.append(durationGauge);
form.append(toneGauge);
}

public void startApp() {
display = Display.getDisplay(this);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
notifyDestroyed();
}
if (c == playCommand){
try {
volume = volumeGauge.getValue();
tone = toneGauge.getValue();
duration = durationGauge.getValue();
Manager.playTone(tone, duration*1000, volume);
} catch (MediaException mex){}
}
}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s