Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package mobileapplication1;
- import java.util.Random;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Form;
- import javax.microedition.lcdui.StringItem;
- import javax.microedition.lcdui.TextField;
- import javax.microedition.midlet.*;
- public class Midlet extends MIDlet implements CommandListener {
- private final Form win;
- private final String[] eng;
- private final String[] pl;
- private final StringItem points;
- private final StringItem word;
- private final StringItem excercise;
- private final TextField answer;
- private final StringItem check;
- private final Command cmdCheck;
- private final Command cmdAgain;
- private final Command cmdEnd;
- static int word_num = 0;
- static int points_num = 0;
- static int index = 0;
- public Midlet() {
- win = new Form("Test z angielskiego");
- eng = new String[5];
- pl = new String[5];
- points = new StringItem("Punkty:", "");
- word = new StringItem("Wyraz:", "");
- excercise = new StringItem("Podaj angielskie tłumaczenie słowa:", "");
- answer = new TextField("Odpowiedź:", "", 30, TextField.ANY);
- check = new StringItem("Odpowiedź jest:", "");
- win.append(points);
- win.append(word);
- win.append(excercise);
- win.append(answer);
- win.append(check);
- cmdCheck = new Command("Sprawdź", Command.ITEM, 0);
- cmdAgain = new Command("Jeszcze raz", Command.ITEM, 0);
- cmdEnd = new Command("Koniec", Command.ITEM, 0);
- win.addCommand(cmdCheck);
- win.addCommand(cmdAgain);
- win.addCommand(cmdEnd);
- win.setCommandListener(this);
- }
- public void startApp() {
- Display display = Display.getDisplay(this);
- display.setCurrent(win);
- getData();
- }
- public void pauseApp() {
- }
- public void destroyApp(boolean unconditional) {
- }
- public void getData() {
- eng[0] = "bike";
- eng[1] = "car";
- eng[2] = "paper";
- eng[3] = "blackboard";
- eng[4] = "keyboard";
- pl[0] = "rower";
- pl[1] = "samochod";
- pl[2] = "papier";
- pl[3] = "tablica";
- pl[4] = "klawiatura";
- word.setText(0 + "");
- points.setText(0 + "");
- random();
- word_num = 0;
- points_num = 0;
- }
- public void random() {
- Random generator = new Random();
- int r = generator.nextInt(eng.length);
- String tekst = pl[r];
- excercise.setText(tekst);
- index = r;
- }
- public void commandAction(Command c, Displayable d) {
- if (c == cmdCheck) {
- String userAnswer = answer.getString();
- word_num += 1;
- word.setText(word_num + "");
- if (userAnswer.equalsIgnoreCase(eng[index])) {
- points_num += 1;
- check.setText("Poprawna" + "");
- points.setText(points_num + "");
- } else {
- check.setText("Niepoprawna" + "");
- }
- answer.setString("");
- random();
- }
- if (c == cmdAgain) {
- getData();
- }
- if (c == cmdEnd) {
- notifyDestroyed();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement