Witam
mam pytanie chce zrobić w jave me odczyt pliku tekstowego.
to już zrobiłem tylko po odczytaniu pliku nie działa cofanie do głównego menu
i na tym się zawiesiłem nie wiem co zrobić proszę o jakąś pomoc z góry dziękuje bardzo za odpowiedz
oto kod mojego zrobionego programu
package hello;
import java.io.;
import javax.microedition.midlet.;
import javax.microedition.lcdui.*;
public class HelloMIDlet extends MIDlet implements CommandListener {
private boolean midletPaused = false;
private Command exitCommand;
private Command backCommand;
private Command helpCommand;
private Form form;
private StringItem stringItem;
private List list;
public HelloMIDlet() {
}
private void initialize() {
}
public void startMIDlet() {
switchDisplayable(null, getList());
}
public void resumeMIDlet() {
}
public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
}
}
public void commandAction(Command command, Displayable displayable) {
if (displayable == form) {
if (command == backCommand) {
switchDisplayable(null, getList());
} else if (command == exitCommand) {
exitMIDlet();
}
} else if (displayable == list) {
if (command == List.SELECT_COMMAND) {
listAction();
} else if (command == exitCommand) {
exitMIDlet();
} else if (command == helpCommand) {
switchDisplayable(null, getForm());
}
}
/*
* else if (displayable == odczyt) {
if (command == backCommand) {
switchDisplayable(null, getList());
}
}
*/
}
public Command getExitCommand() {
if (exitCommand == null) {
exitCommand = new Command("Exit", Command.EXIT, 0);
}
return exitCommand;
}
public Form getForm() {
if (form == null) {
form = new Form("Welcome", new Item[]{getStringItem()});
form.addCommand(getExitCommand());
form.addCommand(getBackCommand());
form.setCommandListener(this);
}
return form;
}
public StringItem getStringItem() {
if (stringItem == null) {
stringItem = new StringItem("Hello", "Hello, World!");
}
return stringItem;
}
public Command getBackCommand() {
if (backCommand == null) {
backCommand = new Command("Cofnij", Command.BACK, 0);
}
return backCommand;
}
public Command getHelpCommand() {
if (helpCommand == null) {
helpCommand = new Command("Help", Command.HELP, 0);
}
return helpCommand;
}
public List getList() {
if (list == null) {
list = new List("list", Choice.IMPLICIT);
list.append("czytanie_plik_1", null);
list.append("czytanie_plik_2", null);
list.append("czytanie_plik_3", null);
list.addCommand(getHelpCommand());
list.addCommand(getExitCommand());
list.setCommandListener(this);
list.setSelectedFlags(new boolean[]{false, false, false});
}
return list;
}
public void listAction() {
String __selectedString = getList().getString(getList().getSelectedIndex());
if (__selectedString != null) {
if (__selectedString.equals("czytanie_plik_1")) {
odczyt();
} else if (__selectedString.equals("czytanie_plik_2")) {
// odczyt();
} else if (__selectedString.equals("czytanie_plik_3")) {
//odczyt();
}
}
}
public Display getDisplay() {
return Display.getDisplay(this);
}
public void exitMIDlet() {
switchDisplayable(null, null);
destroyApp(true);
notifyDestroyed();
}
public void odczyt()
{
String lancuch = "",lancuch2 = "";
int dlugosc = 0;
byte[] bufor = new byte[1024];
Form formatka2 = new Form("opis");
try {
InputStream plik = getClass().getResourceAsStream("plik.txt");
while (dlugosc > -1) {
lancuch2 = new String(bufor, 0, dlugosc);
lancuch += lancuch2;
dlugosc = plik.read(bufor);
}
// Command exit = new Command("exit", Command.EXIT, 1);
// formatka2.addCommand(exit);
formatka2.addCommand(getBackCommand());
formatka2.setCommandListener(this);
formatka2.append(lancuch);
plik.close();
}
catch (Exception e)
{
e.printStackTrace();
}
Display.getDisplay(this).setCurrent(formatka2);
return;
}
public void startApp() {
if (midletPaused) {
resumeMIDlet();
} else {
initialize();
startMIDlet();
}
midletPaused = false;
}
public void pauseApp() {
midletPaused = true;
}
public void destroyApp(boolean unconditional) {
}
}
muszę dodać ścieżkę dostępu do
public void commandAction(Command command, Displayable displayable)
tylko nie wiem jaką
jeszcze raz z góry dziękuje bardzo za odpowiedz