Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.04 KB | None | 0 0
  1. package mobileapplication6;
  2.  
  3. import java.util.Random;
  4. import javax.microedition.midlet.*;
  5. import javax.microedition.lcdui.*;
  6. /**
  7. * @author admin
  8. */
  9. public class Midlet extends MIDlet implements CommandListener{
  10. Random r = new Random();
  11. int wylosowane_slowo = r.nextInt(3) + 1;
  12. private Form okno;
  13. private Command cmdKoniec;
  14. private Command cmdOblicz;
  15. private TextField tf1, tf2, tf3;
  16. private String[] slowka = new String[11];
  17. private String[] slowka2 = new String[9];
  18. private String[] slowka3 = new String[5];
  19. private String [] zgaduj= new String[11];
  20. private String [] zgaduj2= new String[9];
  21. private String [] zgaduj3= new String[5];
  22. private String[] wyswietl = new String[11];
  23. private String[] wyswietl2 = new String[9];
  24. private String[] wyswietl3 = new String[5];
  25. public double proby = 6;
  26. public String li = "";
  27.  
  28. public Midlet() {
  29. okno = new Form("Wisielec");
  30.  
  31. tf1 = new TextField("Szukane slowo: ", null, 50, TextField.ANY);
  32. tf2 = new TextField("Podaj litere: ", null, 1, TextField.ANY);
  33. tf3 = new TextField("Próby ", null, 50, TextField.ANY);
  34. cmdOblicz = new Command("Sprawdź", Command.ITEM, 0);
  35. cmdKoniec = new Command("Koniec", Command.ITEM, 2);
  36. okno.append(tf1);
  37. okno.append(tf2);
  38. okno.append(tf3);
  39.  
  40. slowka[0] = "i";
  41. slowka[1]="n";
  42. slowka[2]="f";
  43. slowka[3]="o";
  44. slowka[4]="r";
  45. slowka[5]="m";
  46. slowka[6]="a";
  47. slowka[7]="t";
  48. slowka[8]="y";
  49. slowka[9]="k";
  50. slowka[10]="a";
  51.  
  52. slowka2[0] = "s";
  53. slowka2[1]="t";
  54. slowka2[2]="o";
  55. slowka2[3]="s";
  56. slowka2[4]="o";
  57. slowka2[5]="w";
  58. slowka2[6]="a";
  59. slowka2[7]="n";
  60. slowka2[8]="a";
  61.  
  62. slowka3[0] = "d";
  63. slowka3[1]="o";
  64. slowka3[2]="m";
  65. slowka3[3]="e";
  66. slowka3[4]="k";
  67.  
  68. zgaduj[0]="_";
  69. zgaduj[1]="_";
  70. zgaduj[2]="_";
  71. zgaduj[3]="_";
  72. zgaduj[4]="_";
  73. zgaduj[5]="_";
  74. zgaduj[6]="_";
  75. zgaduj[7]="_";
  76. zgaduj[8]="_";
  77. zgaduj[9]="_";
  78. zgaduj[10]="_";
  79.  
  80. zgaduj2[0]="_";
  81. zgaduj2[1]="_";
  82. zgaduj2[2]="_";
  83. zgaduj2[3]="_";
  84. zgaduj2[4]="_";
  85. zgaduj2[5]="_";
  86. zgaduj2[6]="_";
  87. zgaduj2[7]="_";
  88. zgaduj2[8]="_";
  89.  
  90. zgaduj3[0]="_";
  91. zgaduj3[1]="_";
  92. zgaduj3[2]="_";
  93. zgaduj3[3]="_";
  94. zgaduj3[4]="_";
  95.  
  96. wyswietl[0]="_";
  97. wyswietl[1]="_";
  98. wyswietl[2]="_";
  99. wyswietl[3]="_";
  100. wyswietl[4]="_";
  101. wyswietl[5]="_";
  102. wyswietl[6]="_";
  103. wyswietl[7]="_";
  104. wyswietl[8]="_";
  105. wyswietl[9]="_";
  106. wyswietl[10]="_";
  107.  
  108. wyswietl2[0]="_";
  109. wyswietl2[1]="_";
  110. wyswietl2[2]="_";
  111. wyswietl2[3]="_";
  112. wyswietl2[4]="_";
  113. wyswietl2[5]="_";
  114. wyswietl2[6]="_";
  115. wyswietl2[7]="_";
  116. wyswietl2[8]="_";
  117.  
  118. wyswietl3[0]="_";
  119. wyswietl3[1]="_";
  120. wyswietl3[2]="_";
  121. wyswietl3[3]="_";
  122. wyswietl3[4]="_";
  123.  
  124. switch(wylosowane_slowo){
  125. case 1:
  126. tf1.setString(zgaduj[0]+" "+zgaduj[1]+" "+zgaduj[2]+" "+zgaduj[3]+" "+zgaduj[4]+" "+zgaduj[5]+" "+ zgaduj[6]+" "+zgaduj[7]+" "+zgaduj[8]+" "+zgaduj[9]+" "+zgaduj[10]);
  127. break;
  128. case 2:
  129. tf1.setString(zgaduj2[0]+" "+zgaduj2[1]+" "+zgaduj2[2]+" "+zgaduj2[3]+" "+zgaduj2[4]+" "+zgaduj2[5]+" "+ zgaduj2[6]+" "+zgaduj2[7]+" "+zgaduj2[8]);
  130. break;
  131. case 3:
  132. tf1.setString(zgaduj3[0]+" "+zgaduj3[1]+" "+zgaduj3[2]+" "+zgaduj3[3]+" "+zgaduj3[4]);
  133. break;
  134. }
  135. }
  136. public void startApp() {
  137. Display ekran = Display.getDisplay(this);
  138. ekran.setCurrent(okno);
  139. okno.addCommand(cmdOblicz);
  140. okno.addCommand(cmdKoniec);
  141. okno.setCommandListener(this);
  142. }
  143.  
  144. public void pauseApp() {
  145. }
  146.  
  147. public void destroyApp(boolean unconditional) {
  148. }
  149.  
  150. public void commandAction(Command cmd, Displayable s) {
  151. if (cmd == cmdOblicz) //przeliczanie temperatury
  152. {
  153. switch(wylosowane_slowo){
  154. case 1:
  155. try
  156. {
  157. String b = tf2.getString();
  158. String a0 = slowka[0];
  159. String a1 = slowka[1];
  160. String a2 = slowka[2];
  161. String a3 = slowka[3];
  162. String a4 = slowka[4];
  163. String a5 = slowka[5];
  164. String a6 = slowka[6];
  165. String a7 = slowka[7];
  166. String a8 = slowka[8];
  167. String a9 = slowka[9];
  168. String a10 = slowka[10];
  169. for(int i = 0; i < 10; i++){
  170. if(slowka[i].equals(b)){
  171. wyswietl[i] = b;
  172. }
  173. }
  174. tf1.setString(wyswietl[0]+" "+wyswietl[1]+" "+wyswietl[2]+" "+wyswietl[3]+" "+wyswietl[4]+" "+wyswietl[5]+" "+wyswietl[6] + " " + wyswietl[7] + " " + wyswietl[8] + " " + wyswietl[9] + " " + wyswietl[10]);
  175. tf3.setString(Double.toString(proby));
  176. }
  177.  
  178. catch (NumberFormatException e)
  179. {
  180. e.printStackTrace();
  181. }
  182. break;
  183. case 2:
  184. try
  185. {
  186. String b = tf2.getString();
  187. String a0 = slowka2[0];
  188. String a1 = slowka2[1];
  189. String a2 = slowka2[2];
  190. String a3 = slowka2[3];
  191. String a4 = slowka2[4];
  192. String a5 = slowka2[5];
  193. String a6 = slowka2[6];
  194. String a7 = slowka2[7];
  195. String a8 = slowka2[8];
  196. if(a0.equals(b))
  197. {
  198. wyswietl2[0]=b;
  199.  
  200. tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
  201.  
  202. }else if(a1.equals(b))
  203. {
  204. wyswietl2[1]=b;
  205.  
  206. tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
  207.  
  208. }else if(a2.equals(b))
  209. {
  210. wyswietl2[2]=b;
  211.  
  212. tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
  213.  
  214. }else if(a3.equals(b))
  215. {
  216. wyswietl2[3]=b;
  217. tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
  218. }else if(a4.equals(b))
  219. {
  220. wyswietl2[4]=b;
  221. tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
  222. }else if(a5.equals(b))
  223. {
  224. wyswietl2[5]=b;
  225. tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
  226. }
  227. else if(a6.equals(b))
  228. {
  229. wyswietl2[6]=b;
  230. tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
  231. }
  232. else if(a7.equals(b))
  233. {
  234. wyswietl2[7]=b;
  235. tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
  236. }
  237. else if(a8.equals(b))
  238. {
  239. wyswietl2[8]=b;
  240. tf1.setString(wyswietl2[0]+" "+wyswietl2[1]+" "+wyswietl2[2]+" "+wyswietl2[3]+" "+wyswietl2[4]+" "+wyswietl2[5]+" "+wyswietl2[6] + " " + wyswietl2[7] + " " + wyswietl2[8]);
  241. }
  242. else
  243. {
  244. proby=proby-1;
  245. tf3.setString(Double.toString(proby));
  246. }
  247. }
  248.  
  249. catch (NumberFormatException e)
  250. {
  251. e.printStackTrace();
  252. }
  253. break;
  254. case 3:
  255. try
  256. {
  257. String b = tf2.getString();
  258. String a0 = slowka3[0];
  259. String a1 = slowka3[1];
  260. String a2 = slowka3[2];
  261. String a3 = slowka3[3];
  262. String a4 = slowka3[4];
  263. if(a0.equals(b))
  264. {
  265. wyswietl3[0]=b;
  266. tf1.setString(wyswietl3[0]+" "+wyswietl3[1]+" "+wyswietl3[2]+" "+wyswietl3[3]+" "+wyswietl3[4]);
  267. }else if(a1.equals(b))
  268. {
  269. wyswietl3[1]=b;
  270. tf1.setString(wyswietl3[0]+" "+wyswietl3[1]+" "+wyswietl3[2]+" "+wyswietl3[3]+" "+wyswietl3[4]);
  271. }else if(a2.equals(b))
  272. {
  273. wyswietl3[2]=b;
  274. tf1.setString(wyswietl3[0]+" "+wyswietl3[1]+" "+wyswietl3[2]+" "+wyswietl3[3]+" "+wyswietl3[4]);
  275. }else if(a3.equals(b))
  276. {
  277. wyswietl3[3]=b;
  278. tf1.setString(wyswietl3[0]+" "+wyswietl3[1]+" "+wyswietl3[2]+" "+wyswietl3[3]+" "+wyswietl3[4]);
  279. }else if(a4.equals(b))
  280. {
  281. wyswietl3[4]=b;
  282. tf1.setString(wyswietl3[0]+" "+wyswietl3[1]+" "+wyswietl3[2]+" "+wyswietl3[3]+" "+wyswietl3[4]);
  283. }
  284. }
  285.  
  286. catch (NumberFormatException e)
  287. {
  288. e.printStackTrace();
  289. }
  290. break;
  291. }
  292.  
  293. }
  294. if (cmd == cmdKoniec)
  295. {
  296. notifyDestroyed();
  297. }
  298. }
  299. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement