iantoya 0 Newbie Poster

I'm making a rock paper scissor game in java mobile application.
I am having a hard time coding on how to get a random value to output a certain message.
And how do I produce a whole number? Not the decimal ones that.
Thanks for the reply.

import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class Midlet extends MIDlet implements CommandListener{
  private Display display;
  private Command exit, generate;
  private StringItem item;
  private Form form;
  private List list;

  public Midlet(){
    display=Display.getDisplay(this);
    form = new Form("RandomNumber");
    exit = new Command("Exit", Command.EXIT,0);
    generate = new Command("Generate", Command.OK,1);    
    item = new StringItem("Number ","");
    form.addCommand(exit);
    form.addCommand(generate);
    form.setCommandListener(this);
    form.append("This Game is made by me!");
    form.append(item);
  }

  public void startApp(){
    display.setCurrent(form);
  }

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){
    notifyDestroyed();
  }

  public void commandAction(Command c, Displayable d){
    String label = c.getLabel();
    if(label.equals("Exit")){
      destroyApp(false);
    }else if(label.equals("Generate")){
      random();
    }
  }

  public void random(){
    Random number = new Random();
    float f = number.nextFloat();
    number.setSeed(System.currentTimeMillis());    
    item.setText(""+(f*100.0f)%3);
  }
  public void showMsg(){
      
      
      Alert alert = new Alert("Generate", 
list.getString(list.getSelectedIndex()), null, null); 
    display.setCurrent(alert);
    


  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.