Selasa, 16 April 2013

Contoh Coding Membuat Read File Text Pada Java


<!–
amazon_ad_tag=”ic0a6-20″;
amazon_ad_width=”728″;
amazon_ad_height=”90″;
amazon_color_border=”206BA2″;
amazon_color_logo=”FFFFFF”;
amazon_color_link=”206BA2″;
amazon_ad_logo=”hide”;
amazon_ad_title=”Toko Online”; //–>
ReadFile.java
importjavax.microedition.lcdui.*;
import java.io.*;
public class ReadFile
extends Form
implements CommandListener {
private ReadFileTextmidlet;
private Display display;
private Command cmExit;
private String help;
private StringItemsi;
publicReadFile(ReadFileTextmidlet, Display display) {
super(“Read File Text”);
this.midlet = midlet;
this.display = display;
if ((help = readHelpText()) != null) {
si = new StringItem(“”, help);
} else
si = new StringItem(“Error”, “File Help TidakDitemukan”);
append(si);
cmExit = new Command(“Keluar”, Command.EXIT, 1);
setCommandListener(this);
addCommand(cmExit);
}
public void commandAction(Command c, Displayable s) {
if (c == cmExit)
midlet.exitMIDlet();
}
private String readHelpText() {
InputStream is = getClass().getResourceAsStream(“help.txt”);
try {
StringBuffersb = new StringBuffer();
intchr, i = 0;
while ((chr = is.read()) != -1)
sb.append((char) chr);
return sb.toString();
} catch (Exception e) {
}
return null;
}
};
ReadFileText.java
importjavax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ReadFileText
extends MIDlet {
Display display;
ReadFile read;
publicReadFileText() {
display = Display.getDisplay(this);
}
public void startApp() {
read = new ReadFile(this, display);
display.setCurrent(read);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {
}
public void exitMIDlet() {
destroyApp(false);
notifyDestroyed();
}
};

1 komentar: