Lap Activity Jeni 4 Level 1

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MidletThreadBackground extends MIDlet {
private Display display;
private ThreadBackgroudCanvas threadCanvas = new ThreadBackgroudCanvas();
public void startApp() {
display = Display.getDisplay(this);
threadCanvas.start();
display.setCurrent(threadCanvas);
}
public Display getDisplay() {
return display;
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) {
exit();
}
public void exit() {
threadCanvas.stop();
System.gc();
notifyDestroyed();
}
}
#————————————————————————————–

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class ThreadBackgroudCanvas extends GameCanvas implements Runnable {
private boolean isPlay;
private long delay;
private int currentX, currentY;
private int width;
private int height;
private int x;
public ThreadBackgroudCanvas() {
super(true);
width = getWidth();
height = getHeight();
currentX = width / 2;
currentY = height / 2;
delay = 20;
}
public void start() {
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop() {
isPlay = false;
}
public void run() {
Graphics g = getGraphics();
while (isPlay == true) {
x++;
if(x<-120) {
x=0;
}else {
x=x-5;
}
drawScreen(g);
try { Thread.sleep(delay); }
catch (InterruptedException ie) { }
}
}
private void drawScreen(Graphics g) {
try {
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
Image image = Image.createImage(“/gbr-bg.png”);
g.drawImage(image, x, (getHeight()-image.getHeight())/2, Graphics.TOP | Graphics.LEFT);
}catch(Exception e){ }
flushGraphics();
}
}
#—————————————————————————————

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MidletThreadObject extends MIDlet {
private Display display;
private ThreadObjectCanvas threadCanvas = new ThreadObjectCanvas();
public void startApp() {
display = Display.getDisplay(this);
threadCanvas.start();
display.setCurrent(threadCanvas);
}
public Display getDisplay() {
return display;
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) {
exit();
}
public void exit() {
threadCanvas.stop();
System.gc();
notifyDestroyed();
}
}
#—————————————————————————————import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class ThreadObjectCanvas extends GameCanvas implements Runnable {
private boolean isPlay;
private long delay;
private int currentX, currentY;
private int width;
private int height;
private int x=0;
private int sw=0;

public ThreadObjectCanvas() {
super(true);
width = getWidth();
height = getHeight();
currentX = width / 2;
currentY = height / 2;
delay = 20;
}

public void start() {
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop() {
isPlay = false;
}

public void run() {
Graphics g = getGraphics();
while (isPlay == true) {
x++;
if(x<-120) {
x=0;
}else{
x=x-5;
}
sw=1-sw;
drawScreen(g);
try { Thread.sleep(delay); }
catch (InterruptedException ie) { }
}
}

private void drawScreen(Graphics g) {
try {
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
Image image = Image.createImage(“/gbr-bg.png”);
g.drawImage(image, x, (getHeight()-image.getHeight())/2, Graphics.TOP | Graphics.LEFT);
String oby=””;
if(sw==0) {
oby=”/obyek1.png”;
}else{
oby=”/obyek2.png”;
}
Image image2 = Image.createImage(oby);
g.drawImage(image2, 40, (getHeight()-image.getHeight())/2, Graphics.TOP | Graphics.LEFT);
}catch(Exception e){ }
flushGraphics();
}
}
#————————————————————————————–import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
public class MidletPlayWav extends MIDlet implements PlayerListener, CommandListener {
private Display display;
private static Player player;
private VolumeControl vc;
private List list;
private Command cmExit, cmStop;
public MidletPlayWav() {
display = Display.getDisplay(this);
}
public void startApp() {
try {
playMedia(“wav.wav”, “wav”);
} catch (Exception e) {
e.printStackTrace();
}
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
public void commandAction(Command c, Displayable s){}
public void exitMIDlet() {
destroyApp(false);
notifyDestroyed();
}
private void playMedia(String file, String p) throws Exception {
player = Manager.createPlayer(getClass().getResourceAsStream(file), “audio/x-wav”);
player.addPlayerListener(this);
player.setLoopCount(-1);
player.prefetch();
player.realize();
vc = (VolumeControl)player.getControl(“VolumeControl”);
if (vc != null) {
vc.setLevel(100);
}
player.start();
}
public void playerUpdate(Player player, String event, Object eventData){ }
}
#————————————————————————————–import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
public class MidletPlayMidi extends MIDlet implements PlayerListener,
CommandListener {
private Display display;
private static Player player;
private VolumeControl vc;
private List list;
private Command cmExit, cmStop;
public MidletPlayMidi() {
display = Display.getDisplay(this);
}
public void startApp() {
try {
playMedia(“mid.mid”, “mid”);
} catch (Exception e) {
e.printStackTrace();
}
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
public void commandAction(Command c, Displayable s){ }
public void exitMIDlet() {
destroyApp(false);
notifyDestroyed();
}
private void playMedia(String file, String p) throws Exception {
player = Manager.createPlayer(getClass().getResourceAsStream(file), “audio/midi”);
player.addPlayerListener(this);
player.setLoopCount(-1);
player.prefetch();
player.realize();
vc = (VolumeControl)player.getControl(“VolumeControl”);
if (vc != null) {
vc.setLevel(100);
}
player.start();
}
public void playerUpdate(Player player, String event, Object eventData){ }
}
#————————————————————————————–import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
public class MidletPlayWavMidi extends MIDlet implements PlayerListener,
CommandListener {
private Display display;
private static Player player;
private VolumeControl vc;
private List list;
private Command cmExit, cmStop;
public MidletPlayWavMidi() {
display = Display.getDisplay(this);
}
public void startApp() {
cmExit = new Command(“Keluar”, Command.EXIT, 1);
cmStop = new Command(“Stop”, Command.OK, 1);
list = new List(“Menu”, List.IMPLICIT);
list.append(“wav”, null);
list.append(“midi”, null);
list.addCommand(cmExit);
list.setCommandListener(this);
display.setCurrent(list);
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
public void commandAction(Command c, Displayable s){
if (c == List.SELECT_COMMAND){
switch (list.getSelectedIndex()){
case 0:
list.addCommand(cmStop);
try {
playMedia(“wav.wav”, “wav”);
} catch (Exception e) {
e.printStackTrace();
}
break;
case 1:
list.addCommand(cmStop);
try {
playMedia(“mid.mid”, “mid”);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}else if(c == cmExit){
exitMIDlet();
}else if(c == cmStop){
try{
player.stop();
if(player != null){
player.close();
}
}catch(Exception e){ }
list.removeCommand(cmStop);
}
}
public void exitMIDlet() {
destroyApp(false);
notifyDestroyed();
player = null;
}
private void playMedia(String file, String p) throws Exception {
if(p.equals(“wav”)){
player = Manager.createPlayer(getClass().getResourceAsStream(file), “audio/x-wav”);
}else if(p.equals(“mid”)){
player = Manager.createPlayer(getClass().getResourceAsStream(file), “audio/midi”);
}
player.addPlayerListener(this);
player.setLoopCount(-1);
player.prefetch();
player.realize();
vc = (VolumeControl)player.getControl(“VolumeControl”);
if (vc != null) {
vc.setLevel(100);
}
player.start();
}
public void playerUpdate(Player player, String event, Object eventData){ }
}

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