Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mobileapplication6;
- import java.util.Random;
- import javax.microedition.midlet.*;
- import javax.microedition.lcdui.*;
- /**
- * @author admin
- */
- public class Midlet extends MIDlet implements CommandListener{
- Random r = new Random();
- int wylosowane_slowo = r.nextInt(3) + 1;
- private Form okno;
- private Command cmdKoniec;
- private Command cmdOblicz;
- private TextField tf1, tf2, tf3;
- private String[] slowka = new String[11];
- private String[] slowka2 = new String[9];
- private String[] slowka3 = new String[5];
- private String [] zgaduj= new String[11];
- private String [] zgaduj2= new String[9];
- private String [] zgaduj3= new String[5];
- private String[] wyswietl = new String[11];
- private String[] wyswietl2 = new String[9];
- private String[] wyswietl3 = new String[5];
- public double proby = 6;
- public String li = "";
- public Midlet() {
- okno = new Form("Wisielec");
- tf1 = new TextField("Szukane slowo: ", null, 50, TextField.ANY);
- tf2 = new TextField("Podaj litere: ", null, 1, TextField.ANY);
- tf3 = new TextField("Próby ", null, 50, TextField.ANY);
- cmdOblicz = new Command("Sprawdź", Command.ITEM, 0);
- cmdKoniec = new Command("Koniec", Command.ITEM, 2);
- okno.append(tf1);
- okno.append(tf2);
- okno.append(tf3);
- slowka[0] = "i";
- slowka[1]="n";
- slowka[2]="f";
- slowka[3]="o";
- slowka[4]="r";
- slowka[5]="m";
- slowka[6]="a";
- slowka[7]="t";
- slowka[8]="y";
- slowka[9]="k";
- slowka[10]="a";
- slowka2[0] = "s";
- slowka2[1]="t";
- slowka2[2]="o";
- slowka2[3]="s";
- slowka2[4]="o";
- slowka2[5]="w";
- slowka2[6]="a";
- slowka2[7]="n";
- slowka2[8]="a";
- slowka3[0] = "d";
- slowka3[1]="o";
- slowka3[2]="m";
- slowka3[3]="e";
- slowka3[4]="k";
- zgaduj[0]="_";
- zgaduj[1]="_";
- zgaduj[2]="_";
- zgaduj[3]="_";
- zgaduj[4]="_";
- zgaduj[5]="_";
- zgaduj[6]="_";
- zgaduj[7]="_";
- zgaduj[8]="_";
- zgaduj[9]="_";
- zgaduj[10]="_";
- zgaduj2[0]="_";
- zgaduj2[1]="_";
- zgaduj2[2]="_";
- zgaduj2[3]="_";
- zgaduj2[4]="_";
- zgaduj2[5]="_";
- zgaduj2[6]="_";
- zgaduj2[7]="_";
- zgaduj2[8]="_";
- zgaduj3[0]="_";
- zgaduj3[1]="_";
- zgaduj3[2]="_";
- zgaduj3[3]="_";
- zgaduj3[4]="_";
- wyswietl[0]="_";
- wyswietl[1]="_";
- wyswietl[2]="_";
- wyswietl[3]="_";
- wyswietl[4]="_";
- wyswietl[5]="_";
- wyswietl[6]="_";
- wyswietl[7]="_";
- wyswietl[8]="_";
- wyswietl[9]="_";
- wyswietl[10]="_";
- wyswietl2[0]="_";
- wyswietl2[1]="_";
- wyswietl2[2]="_";
- wyswietl2[3]="_";
- wyswietl2[4]="_";
- wyswietl2[5]="_";
- wyswietl2[6]="_";
- wyswietl2[7]="_";
- wyswietl2[8]="_";
- wyswietl3[0]="_";
- wyswietl3[1]="_";
- wyswietl3[2]="_";
- wyswietl3[3]="_";
- wyswietl3[4]="_";
- switch(wylosowane_slowo){
- case 1:
- tf1.setString(zgaduj[0]+" "+zgaduj[1]+" "+zgaduj[2]+" "+zgaduj[3]+" "+zgaduj[4]+" "+zgaduj[5]+" "+ zgaduj[6]+" "+zgaduj[7]+" "+zgaduj[8]+" "+zgaduj[9]+" "+zgaduj[10]);
- break;
- case 2:
- tf1.setString(zgaduj2[0]+" "+zgaduj2[1]+" "+zgaduj2[2]+" "+zgaduj2[3]+" "+zgaduj2[4]+" "+zgaduj2[5]+" "+ zgaduj2[6]+" "+zgaduj2[7]+" "+zgaduj2[8]);
- break;
- case 3:
- tf1.setString(zgaduj3[0]+" "+zgaduj3[1]+" "+zgaduj3[2]+" "+zgaduj3[3]+" "+zgaduj3[4]);
- break;
- }
- }
- public void startApp() {
- Display ekran = Display.getDisplay(this);
- ekran.setCurrent(okno);
- okno.addCommand(cmdOblicz);
- okno.addCommand(cmdKoniec);
- okno.setCommandListener(this);
- }
- public void pauseApp() {
- }
- public void destroyApp(boolean unconditional) {
- }
- public void commandAction(Command cmd, Displayable s) {
- if (cmd == cmdOblicz) //przeliczanie temperatury
- {
- switch(wylosowane_slowo){
- case 1:
- try
- {
- String b = tf2.getString();
- String a0 = slowka[0];
- String a1 = slowka[1];
- String a2 = slowka[2];
- String a3 = slowka[3];
- String a4 = slowka[4];
- String a5 = slowka[5];
- String a6 = slowka[6];
- String a7 = slowka[7];
- String a8 = slowka[8];
- String a9 = slowka[9];
- String a10 = slowka[10];
- for(int i = 0; i < 10; i++){
- if(slowka[i].equals(b)){
- wyswietl[i] = b;
- }
- }
- tf1.setString(wyswietl[0]+" "+wyswietl[1]+" "+wyswietl[2]+" "+wyswietl[3]+" "+wyswietl[4]+" "+wyswietl[5]+" "+wyswietl[6] + " " + wyswietl[7] + " " + wyswietl[8] + " " + wyswietl[9] + " " + wyswietl[10]);
- tf3.setString(Double.toString(proby));
- }
- catch (NumberFormatException e)
- {
- e.printStackTrace();
- }
- break;
- case 2:
- try
- {
- String b = tf2.getString();
- String a0 = slowka2[0];
- String a1 = slowka2[1];
- String a2 = slowka2[2];
- String a3 = slowka2[3];
- String a4 = slowka2[4];
- String a5 = slowka2[5];
- String a6 = slowka2[6];
- String a7 = slowka2[7];
- String a8 = slowka2[8];
- if(a0.equals(b))
- {
- wyswietl2[0]=b;
- tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
- }else if(a1.equals(b))
- {
- wyswietl2[1]=b;
- tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
- }else if(a2.equals(b))
- {
- wyswietl2[2]=b;
- tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
- }else if(a3.equals(b))
- {
- wyswietl2[3]=b;
- tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
- }else if(a4.equals(b))
- {
- wyswietl2[4]=b;
- tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
- }else if(a5.equals(b))
- {
- wyswietl2[5]=b;
- tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
- }
- else if(a6.equals(b))
- {
- wyswietl2[6]=b;
- tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
- }
- else if(a7.equals(b))
- {
- wyswietl2[7]=b;
- tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
- }
- else if(a8.equals(b))
- {
- wyswietl2[8]=b;
- tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
- }
- else
- {
- proby=proby-1;
- tf3.setString(Double.toString(proby));
- }
- }
- catch (NumberFormatException e)
- {
- e.printStackTrace();
- }
- break;
- case 3:
- try
- {
- String b = tf2.getString();
- String a0 = slowka3[0];
- String a1 = slowka3[1];
- String a2 = slowka3[2];
- String a3 = slowka3[3];
- String a4 = slowka3[4];
- if(a0.equals(b))
- {
- wyswietl3[0]=b;
- tf1.setString(wyswietl3[0]+" "+wyswietl3[1]+" "+wyswietl3[2]+" "+wyswietl3[3]+" "+wyswietl3[4]);
- }else if(a1.equals(b))
- {
- wyswietl3[1]=b;
- tf1.setString(wyswietl3[0]+" "+wyswietl3[1]+" "+wyswietl3[2]+" "+wyswietl3[3]+" "+wyswietl3[4]);
- }else if(a2.equals(b))
- {
- wyswietl3[2]=b;
- tf1.setString(wyswietl3[0]+" "+wyswietl3[1]+" "+wyswietl3[2]+" "+wyswietl3[3]+" "+wyswietl3[4]);
- }else if(a3.equals(b))
- {
- wyswietl3[3]=b;
- tf1.setString(wyswietl3[0]+" "+wyswietl3[1]+" "+wyswietl3[2]+" "+wyswietl3[3]+" "+wyswietl3[4]);
- }else if(a4.equals(b))
- {
- wyswietl3[4]=b;
- tf1.setString(wyswietl3[0]+" "+wyswietl3[1]+" "+wyswietl3[2]+" "+wyswietl3[3]+" "+wyswietl3[4]);
- }
- }
- catch (NumberFormatException e)
- {
- e.printStackTrace();
- }
- break;
- }
- }
- if (cmd == cmdKoniec)
- {
- notifyDestroyed();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement