This is a Java ME question. I am using Netbeans 7.0. The setting is CLDC 1.1, MIDP 2.0, DefaultCldcJtwiPhone1, my cell is a Nokia 5130 Express Music. I did this code without any loops. Still this code not working with any loops, AND when the Random function is call, all display the same numbers ( except in my cell, the "lotoMax" show different numbers but not the "6/49". Go ahead, try it this code, and "select" 6/49 or lotoMax, place a loop and try again, still not working right. the code will compile & run , BUT not run well. I know I am a NooB here, I need some help and tell me Why the loop is not executed and the numbers not display right. I getting frustrated here.
My question : Why it did not work, How can I fix it and any help.
Here the code :
package Lotteryselect;
import javax.microedition.lcdui.*;
import java.io.*;
import java.lang.*;
import java.util.*;
import javax.microedition.midlet.*;
public class LotteryselectMidlet extends MIDlet implements CommandListener
{
private Display display,display649,displaylotomax;
private List menu;
private TextBox input;
private Form form649,formlotomax;
int set649,setlotomax;
int bal1,bal2,bal3,bal4,bal5,bal6;
static final Command backCommand = new Command("Back", Command.BACK, 0);
static final Command mainMenuCommand = new Command("Main", Command.SCREEN, 1);
static final Command exitCommand = new Command("Exit", Command.STOP, 2);
private String currentMenu;
public void startApp() throws MIDletStateChangeException
{
display = Display.getDisplay(this);
menu = new List("Lottery Selection", Choice.IMPLICIT);
menu.append("Lotto 6/49", null);
menu.append("Lotto Max", null);
menu.append("Item3", null);
menu.append("Item4", null);
menu.addCommand(exitCommand);
menu.setCommandListener(this);
mainMenu();
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
void mainMenu() {
display.setCurrent(menu);
currentMenu = "Main";
}
public void prepare() {
input = new TextBox("Enter some text: ", "", 5, TextField.ANY);
input.addCommand(backCommand);
input.setCommandListener(this);
input.setString("");
display.setCurrent(input);
}
public void lotto649 ()
{
int a,b,c,d,e,f,i,count;
int[] bal649 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,
38,39,40,41,42,43,44,45,46,47,48,49};
a = new Random().nextInt(49);
bal1=bal649[a];
b = new Random().nextInt(49);
bal2=bal649[b];
c = new Random().nextInt(49);
bal3=bal649[c];
d = new Random().nextInt(49);
bal4=bal649[d];
e = new Random().nextInt(49);
bal5=bal649[e];
f = new Random().nextInt(49);
bal6=bal649[f];
form649 = new Form("6/49 Numbers");
form649.append("\n\n\n");
form649.append(bal1+" "+bal2+" "+bal3+" "+bal4+" "+bal5+" "+bal6);
display649 = Display.getDisplay(this);
display649.setCurrent(form649);
form649.addCommand(backCommand);
form649.setCommandListener(this);
currentMenu = "Lotto 6/49";
}
public void lottomax ()
{
formlotomax = new Form("Loto Max Numbers");
formlotomax.append("\n\n\n");
setlotomax = new Random().nextInt(48);
formlotomax.append(setlotomax+" ");
setlotomax = new Random().nextInt(48);
formlotomax.append(setlotomax+" ");
setlotomax = new Random().nextInt(48);
formlotomax.append(setlotomax+" ");
setlotomax = new Random().nextInt(48);
formlotomax.append(setlotomax+" ");
setlotomax = new Random().nextInt(48);
formlotomax.append(setlotomax+" ");
setlotomax = new Random().nextInt(48);
formlotomax.append(setlotomax+" ");
displaylotomax = Display.getDisplay(this);
displaylotomax.setCurrent(formlotomax);
formlotomax.addCommand(backCommand);
formlotomax.setCommandListener(this);
currentMenu = "Lotto Max";
}
public void testItem3()
{
prepare();
currentMenu = "item3";
}
public void testItem4()
{
prepare();
currentMenu = "item4";
}
public void commandAction(Command c, Displayable d)
{
String label = c.getLabel();
if (label.equals("Exit")) {
destroyApp(true);
} else if (label.equals("Back")) {
if(currentMenu.equals("Lotto 6/49") || currentMenu.equals("Lotto Max") ||
currentMenu.equals("item3") || currentMenu.equals("item4")) {
mainMenu();
}
} else {
List down = (List)display.getCurrent();
switch(down.getSelectedIndex()) {
case 0: lotto649 ();break;
case 1: lottomax ();break;
case 2: testItem3();break;
case 3: testItem4();break;
}
}
}
}