AddCommand Help

Hi Everybody,
Am writing a J2ME application which requires users to log into the application. A snippet of the code is mentioned here
public LoginScreen(midlet) {
super("Login");
this.midlet = midlet;
_user = new TextField("Code", "", 10, TextField.NUMERIC);
_pass = new TextField("Pass", "", 10, TextField.PASSWORD);
append(_user);
append(_pass);
addCommand(_login = new Command("Login",Command.SCREEN, 1));
addCommand(_cancel = new Command("Exit",Command.SCREEN, 2));
setCommandListener(this);
I have a problem with this. With the current code, the left soft key of the mobile device is getting assigned with 'LOGIN' and the right softkey is getting assigned with 'EXIT. Is there a way where I can swap the two i.e. can i have the left soft key of the mobile device to have the EXIT command assigned and LOGIN to the right soft key.
Any help would be a major contribution
Ramesh

Generally speaking, it's up to the device's implementation to decide where a Command will be placed. You have no way to directly assign a specific command to a specific soft-key. You can only "influence" the implementation's decision of where to put the Command, by using the commandType and priority parameters. If the Command's commandType is Command.EXIT, then the implementation will try to put the Command on the soft-button that is usually reserved for the "negative" commands (like "Back", "Exit", "Quit", "Cancel"). But the exact location depends on the phone and on the number and types of Commands you add to a screen.
You can try playing around with these values to get it on either side. I would recommend:
addCommand(_login = new Command("Login",Command.OK, 1)); // OK since it's a "positive" action
addCommand(_cancel = new Command("Exit",Command.EXIT, 2)); // EXIT since it's a "negative" actionshmoove

Similar Messages

  • Error When Using a destroyApp(true)

    Hello,
    I'm starting in Java ME development, but when i finished the code, that i'm developing using Eclipse, it shows that my code have an error, with that red x in the left of the code line, here is the code:
    package comm;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Form;
    public class comm extends MIDlet implements CommandListener {
        private Display display;
        private Form inicio;
        private Form logado;
        private Form recusado;
        private Command cancelar;
        private Command login;
        private Command info;
        private Command help;
        private Command naousuario;
        private Command voltar;
         public comm() {
              inicio = new Form("Entrar");
              cancelar = new Command("Cancelar", Command.CANCEL, 0);
              login = new Command("Login", Command.OK, 1);
              info = new Command("Info", Command.OK, 1);
              help = new Command("Help", Command.OK, 1);
              inicio = new Form("Logado");
              recusado = new Form("Não Usuário");
              logado = new Form("Logado");
              naousuario = new Command("Não Usuário", Command.OK, 1);
              voltar = new Command("Voltar", Command.BACK, 0);
         protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
              notifyDestroyed();
         protected void pauseApp() {
              // TODO Auto-generated method stub
         protected void startApp() throws MIDletStateChangeException {
              // Form Inicial
              display = Display.getDisplay(this);
              inicio.addCommand(cancelar);
              inicio.addCommand(login);
              inicio.addCommand(info);
              inicio.addCommand(help);
              inicio.addCommand(naousuario);
              inicio.setCommandListener(this);
              // Form Usuário Logado
              logado.addCommand(info);
              logado.addCommand(voltar);
              logado.setCommandListener(this);
              // Form Não Usuário
              recusado.addCommand(voltar);
              recusado.setCommandListener(this);
              display.setCurrent(inicio);
         public void commandAction(Command c, Displayable d) {
              if (c == cancelar) {
                   destroyApp(true);
              } else if (c == login) {
                   display.setCurrent(logado);
              } else if (c == naousuario) {
                   display.setCurrent(recusado);
              } else if (c == voltar) {
                   display.setCurrent(inicio);
    }The error is in the line 67, and the error detail that is in the Problems tab is here:
    Unhandled exception type MIDletStateChangeException
    What is wrong?
    Thanks,
    Nathan Paulino Campos

    As far as I understand, the way you use destroyApp(true) in commandAction is wrong. Replace it with notifyDestroyed()
    If you're interested, check [MIDlet class javadocs|http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/midlet/MIDlet.html] to understand why is that.
    I would also remove notifyDestroyed() from destroyApp. If Eclipse uses Wireless Toolkit as emulator, you can take a look into source code of application demos that are included in WTK to find out how to use these methods properly.

  • Urgent help needed: how to display a list of records on the screen

    Hello,
    This is very urgent. Can anyone help me. I have posted this query of mine before also but still no reply came. My whole application is dependent on this problem. Actually I am developing an application for mobile phone using MIDP. I have a record store which contains personal details for users. I am able to add records to the record store. Now I want that these records can be edited. For this I want to display a list of firstname field on the screen (and not console) so that i can select a user to edit its details. I have written the code to read the records and individual fields and display it on the console but i want to display that list on screen. I tried list and array but it s giving some error.
    I am giving the code to read the records below. Please tell me how can I display it in a list on the screen.
    public void readStream(){
    try
    byte[] recData=new byte[50];
    String varname;
    ByteArrayInputStream strmBytes = new ByteArrayInputStream(recData);
    DataInputStream strmData=new DataInputStream(strmBytes);
    if (rsperdt.getNumRecords() > 0){
    ComparatorString comp=new ComparatorString();
    int i=1;
    RecordEnumeration re=rsperdt.enumerateRecords(null, comp, false);
    while(re.hasNextElement()){
    rsperdt.getRecord(re.nextRecordId(), recData,0);
    System.out.println("Record #" + i );
    varname = strmData.readUTF();
    System.out.println("Name #"+varname);
    System.out.println("---------------------------");
    i=i+1;
    strmBytes.reset();
    comp.compareStringClose();
    re.destroy();
    strmBytes.close();
    catch(Exception e){
    System.err.println("read Records class:read");
    }

    I could not understand ur point "post the code in tags". I am pasting the code below. Please help as my whole application is stuck due to this problem and I have a deadline of 7th oct.
    This midlet is getting called from some other midlet.
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import javax.microedition.rms.*;
    import java.io.*;
    import java.util.*;
    public class frmread extends Form implements CommandListener
    static final String rec_store="db_per";
    private RecordStore rsperdt=null;
    private Vector vecname;
    private ChoiceGroup chname;
    private boolean flagSortByPriority = false, flagShowPriority = true;
    private Form fmmain;
    private Command cmdBack;
    private teledoc midlet;
    public frmread(String title, teledoc midlet)
    super(title);
    this.midlet = midlet;
    openRecStore();
    this.setCommandListener(this);
         chname = new ChoiceGroup("new", Choice.EXCLUSIVE);
         vecname = new Vector();
         cmdBack = new Command("Back", Command.BACK, 1);
    fmmain = new Form("Record Search");
         addCommand(cmdBack);
    setCommandListener(this);
    readStream();
         rebuildTodoList();
         closeRecStore();
    * Process events for this form only
    protected void rebuildTodoList()
    for(int j=chname.size(); j>0; j--)
         chname.delete(j-1);
         int priority;
         todoitem item;
         String text;
         StringBuffer sb;
         for (int j=0; j<vecname.size(); j++)
              item=(todoitem) vecname.elementAt(j);
              priority = item.getPriority();
              text = item.getText();
              sb = new StringBuffer((flagShowPriority ? (Integer.toString(priority) + "-"): ""));
              sb.append(text);
              chname.append(sb.toString(), null);
    public void commandAction(Command c, Displayable s)
    if (c == cmdBack){
    midlet.displayteledoc();
    public void readStream(){
    try
    byte[] recData=new byte[100];
    String varname;
    int varname1=0;
         ByteArrayInputStream strmBytes = new ByteArrayInputStream(recData);
         DataInputStream strmData=new DataInputStream(strmBytes);
         if (rsperdt.getNumRecords() > 0){
    ComparatorString comp=new ComparatorString();
    int i=1;
              int id = 1;
              vecname.removeAllElements();
              RecordEnumeration re=rsperdt.enumerateRecords(null, comp, false);
    while(re.hasNextElement()){
         rsperdt.getRecord(re.nextRecordId(), recData,0);
    System.out.println("Record #" + i );
    varname = strmData.readUTF();
                   varname1 = strmData.readInt();
                   id = re.nextRecordId();
                   System.out.println("Name #"+varname);
                   todoitem item = new todoitem(varname1, varname, id);
                   vecname.addElement(item);
                   System.out.println("---------------------------");
                   i=i+1;
    strmBytes.reset();
              comp.compareStringClose();
              re.destroy();
    strmBytes.close();
    catch(Exception e){
    System.err.println("read Records class:read");
    public void openRecStore(){
    try{
    rsperdt=RecordStore.openRecordStore("db_per",true);
    catch(RecordStoreException e){
    db(e.toString());
    public void closeRecStore(){
    try{
    rsperdt.closeRecordStore();
    catch(Exception e){
    db(e.toString());
    public void db(String str){
    System.err.println("Msg:" + str);
    class ComparatorString implements RecordComparator{
    private byte[] recData = new byte[20];
    private ByteArrayInputStream strmBytes = null;
    private DataInputStream strmDataType = null;
    public void compareStringClose(){
    try{
    if(strmBytes != null)
         strmBytes.close();
    if(strmDataType != null)
         strmDataType.close();
         catch (Exception e)
    public int compare(byte[] rec1, byte[] rec2)
         String str1, str2;
         try {
              int maxsize = Math.max(rec1.length, rec2.length);
              if (maxsize > recData.length)
              recData = new byte[maxsize];
                   strmBytes = new ByteArrayInputStream(rec1);
                   strmDataType = new DataInputStream(strmBytes);
                   str1=strmDataType.readUTF();
                   strmBytes = new ByteArrayInputStream(rec2);
                   strmDataType = new DataInputStream(strmBytes);
                   str2=strmDataType.readUTF();
                   int result=str1.compareTo(str2);
                   if (result == 0)
                   return RecordComparator.EQUIVALENT;
                   else if (result < 0)
                   return RecordComparator.PRECEDES;
                   else
                   return RecordComparator.FOLLOWS;
                   catch (Exception e)
                   return RecordComparator.EQUIVALENT;

  • Please someone help me with this code..

    hi, i have a big problem trying to figure out how to do this, i get this code somewhere in the net, so it's not me who code this, that's why i got this problem.
    this is a MIDlet games, something like gallaga. i like to add some features like the UP and DOWN movement and also i have a problem with his "fire", i can only shoot once after the fire image is gone in the screen, what i liked to have is even i pressed the fire button and press it again the fire will not gone, what i mean continues fire if i pressed everytime the fire button.
    i will post the code here so you can see it and give me some feedback. i need this badly, hoping to all you guys! thanks..for this forum.
    ----CODE BEGIN ---------------
    import java.io.IOException;
    import java.io.PrintStream;
    import java.util.Random;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.rms.RecordStore;
    import javax.microedition.rms.RecordStoreException;
    public class MobileGalaga extends MIDlet
    implements CommandListener, Runnable
    class ScoreScreen extends Canvas
    public void paint(Graphics g)
    g.setColor(0xffffff);
    g.fillRect(0, 0, MobileGalaga.WIDTH, MobileGalaga.HEIGHT);
    g.setColor(0x160291);
    g.setFont(MobileGalaga.fs);
    g.drawString("Help", MobileGalaga.CENTERW, 2, 17);
    g.setColor(0);
    g.drawString("Use left/right and fire", MobileGalaga.CENTERW, 20, 17);
    g.drawString("to destory the", MobileGalaga.CENTERW, 30, 17);
    g.drawString("incoming alien MobileGalaga", MobileGalaga.CENTERW, 40, 17);
    public void keyPressed(int i)
    int j = getGameAction(i);
    if(j == 8)
    display.setCurrent(titlescreen);
    ScoreScreen()
    class TitleScreen extends Canvas
    public void paint(Graphics g)
    g.setColor(0xffffff);
    g.fillRect(0, 0, MobileGalaga.WIDTH, MobileGalaga.HEIGHT);
    g.drawImage(MobileGalaga.logoimg, MobileGalaga.CENTERW, 15, 17);
    g.setColor(0);
    g.setFont(MobileGalaga.fs);
    g.drawString("Press 5 to", MobileGalaga.CENTERW, 43, 17);
    g.drawString("see help", MobileGalaga.CENTERW, 53, 17);
    public void keyPressed(int i)
    int j = getGameAction(i);
    if(j == 8)
    display.setCurrent(scorescreen);
    TitleScreen()
    class MainScreen extends Canvas
    public void paint(Graphics g)
    offg.setColor(0xffffff);
    offg.fillRect(0, 0, MobileGalaga.WIDTH, MobileGalaga.HEIGHT);
    for(int i = 0; i < MobileGalaga.slen; i++)
    if(!MobileGalaga.dead)
    offg.drawImage(MobileGalaga.alienimg[MobileGalaga.frame[i]], MobileGalaga.x[i], MobileGalaga.y[i], 17);
    if(!MobileGalaga.playerdead)
    offg.drawImage(MobileGalaga.playerimg, MobileGalaga.px, MobileGalaga.py, 17);
    } else
    if(MobileGalaga.explodeframe < 3)
    offg.drawImage(MobileGalaga.explosionimg[MobileGalaga.explodeframe], MobileGalaga.px, MobileGalaga.py, 17);
    MobileGalaga.explodeframe++;
    if(!MobileGalaga.gameover)
    MobileGalaga.playerpause++;
    if(MobileGalaga.playerpause < 50)
    MobileGalaga.playerpause++;
    } else
    MobileGalaga.playerdead = false;
    MobileGalaga.playerpause = 0;
    MobileGalaga.px = MobileGalaga.CENTERW;
    offg.setColor(0);
    offg.drawString(MobileGalaga.scorestr, MobileGalaga.WIDTH, 0, 24);
    offg.drawImage(MobileGalaga.playerimg, 0, 0, 20);
    offg.drawString(MobileGalaga.lives + "", 12, 0, 20);
    if(MobileGalaga.laser)
    offg.drawLine(MobileGalaga.laserx, MobileGalaga.lasery, MobileGalaga.laserx, MobileGalaga.lasery + 4);
    if(MobileGalaga.showscores)
    for(int j = 0; j < 5; j++)
    if(j == MobileGalaga.rank)
    offg.setColor(0xff0000);
    else
    offg.setColor(0);
    offg.drawString((j + 1) + " .... " + getScoreStr(MobileGalaga.highscore[j]), MobileGalaga.CENTERW, 20 + j * 10, 17);
    if(MobileGalaga.showmessage)
    offg.setColor(0xff0000);
    offg.drawString(MobileGalaga.msg, MobileGalaga.CENTERW, MobileGalaga.CENTERH, 17);
    MobileGalaga.messagepause++;
    if(MobileGalaga.messagepause > 20)
    MobileGalaga.showmessage = false;
    MobileGalaga.messagepause = 0;
    if(MobileGalaga.gameover)
    MobileGalaga.showscores = true;
    else
    if(MobileGalaga.wavecomplete)
    initWave();
    g.drawImage(offimg, 0, 0, 20);
    public void keyPressed(int i)
    int j = getGameAction(i);
    if(j == 2)
    MobileGalaga.playerLeft = true;
    else
    if(j == 5)
    MobileGalaga.playerRight = true;
    else
    if(j == 8)
    fireLaser();
    public void keyReleased(int i)
    int j = getGameAction(i);
    if(j == 2)
    MobileGalaga.playerLeft = false;
    else
    if(j == 5)
    MobileGalaga.playerRight = false;
    private Image offimg;
    private Graphics offg;
    public MainScreen()
    offimg = Image.createImage(getWidth(), getHeight());
    offg = offimg.getGraphics();
    offg.setFont(MobileGalaga.fs);
    public MobileGalaga()
    rand = new Random();
    display = Display.getDisplay(this);
    mainscreen = new MainScreen();
    titlescreen = new TitleScreen();
    scorescreen = new ScoreScreen();
    WIDTH = mainscreen.getWidth();
    HEIGHT = mainscreen.getHeight();
    CENTERW = WIDTH / 2;
    CENTERH = HEIGHT / 2;
    exitCommand = new Command("Exit", 7, 1);
    playCommand = new Command("Play", 1, 1);
    quitCommand = new Command("Quit", 1, 1);
    againCommand = new Command("Again", 1, 1);
    nullCommand = new Command("", 1, 1);
    try
    alienimg[0] = Image.createImage("/alien1.png");
    alienimg[1] = Image.createImage("/alien2.png");
    explosionimg[0] = Image.createImage("/explosion1.png");
    explosionimg[1] = Image.createImage("/explosion2.png");
    explosionimg[2] = Image.createImage("/explosion3.png");
    playerimg = Image.createImage("/player.png");
    logoimg = Image.createImage("/logo.png");
    catch(IOException ioexception)
    db("Couldn't get images!");
    imgW = alienimg[0].getWidth();
    imgH = alienimg[0].getHeight();
    edgeH = imgW / 2;
    edgeV = imgH / 2;
    pimgW = playerimg.getWidth();
    pimgH = playerimg.getHeight();
    pedgeH = pimgW / 2;
    pedgeV = pimgH / 2;
    highscore = getHighScores();
    public void run()
    while(runner)
    rp();
    updatePos();
    try
    MobileGalaga _tmp = this;
    Thread.sleep(75L);
    catch(InterruptedException interruptedexception)
    db("interrupted");
    runner = false;
    MobileGalaga _tmp1 = this;
    Thread.yield();
    public void startApp()
    throws MIDletStateChangeException
    display.setCurrent(titlescreen);
    addBeginCommands(titlescreen, false);
    addBeginCommands(scorescreen, false);
    addPlayCommands(mainscreen, false);
    public void pauseApp()
    public void destroyApp(boolean flag)
    runner = false;
    th = null;
    private void rp()
    mainscreen.repaint();
    private void startGame()
    initGame();
    if(th == null)
    th = new Thread(this);
    runner = true;
    th.start();
    private void initGame()
    px = CENTERW;
    py = HEIGHT - pedgeV - pimgH;
    packcount = 0;
    lives = 3;
    score = 0;
    scorestr = "000000";
    rank = -1;
    difficulty = 400;
    wave = 1;
    initWave();
    private void initWave()
    for(int i = 0; i < slen; i++)
    frame[i] = i % 2;
    x[i] = packX[i] = sposX[i];
    y[i] = packY[i] = sposY[i];
    dx[i] = packdx = alien_dx_right;
    dy[i] = packdy = alien_dy_right;
    dxcount[i] = dycount[i] = 0;
    pmode[i] = 0;
    flying[i] = false;
    dead[i] = false;
    playerLeft = false;
    playerRight = false;
    laser = false;
    playerdead = false;
    showscores = false;
    showmessage = false;
    gameover = false;
    wavecomplete = false;
    playerpause = 0;
    messagepause = 0;
    killed = 0;
    private void updatePos()
    if(playerLeft)
    updatePlayerPos(-2);
    else
    if(playerRight)
    updatePlayerPos(2);
    fly = Math.abs(rand.nextInt() % difficulty);
    if(fly < slen && !flying[fly] && !dead[fly])
    if(x[fly] < CENTERW)
    setDX(fly, alien_dx_flyright, 2);
    setDY(fly, alien_dy_flyright, 2);
    } else
    setDX(fly, alien_dx_flyleft, 2);
    setDY(fly, alien_dy_flyleft, 2);
    flying[fly] = true;
    for(int i = 0; i < slen; i++)
    if(!dead[i])
    if(!flying[i])
    if(x[i] + edgeH + dx[i][dxcount[i]] > WIDTH)
    changePackDir(alien_dx_left, alien_dy_left);
    if((x[i] - edgeH) + dx[i][dxcount[i]] < 0)
    changePackDir(alien_dx_right, alien_dy_right);
    } else
    if(y[i] + edgeV + dy[i][dycount[i]] > HEIGHT)
    x[i] = packX[i];
    y[i] = packY[i];
    flying[i] = false;
    setDX(i, packdx, 0);
    setDY(i, packdy, 0);
    if(!playerdead && y[i] <= py + pedgeV && y[i] >= py - pedgeV && x[i] <= px + pedgeH && x[i] >= px - pedgeH)
    playerHit();
    if(laser && lasery <= y[i] + edgeV && lasery >= y[i] - edgeV && laserx <= x[i] + edgeH && laserx >= x[i] - edgeH)
    alienHit(i);
    for(int j = 0; j < slen; j++)
    if(!dead[j])
    if(framecount == 3)
    frame[j] = frame[j] + 1 < 2 ? 1 : 0;
    lastx = x[j];
    lasty = y[j];
    x[j] += dx[j][dxcount[j]];
    y[j] += dy[j][dycount[j]];
    if(pmode[j] == 0)
    dxcount[j] = dxcount[j] + 1 < dx[j].length ? dxcount[j] + 1 : 0;
    dycount[j] = dycount[j] + 1 < dy[j].length ? dycount[j] + 1 : 0;
    } else
    if(pmode[j] == 2)
    dxcount[j] = dxcount[j] + 1 < dx[j].length ? dxcount[j] + 1 : dxcount[j];
    dycount[j] = dycount[j] + 1 < dy[j].length ? dycount[j] + 1 : dycount[j];
    packX[j] += packdx[packcount];
    packY[j] += packdy[packcount];
    packcount = packcount + 1 < packlen ? packcount + 1 : 0;
    framecount = framecount + 1 < 4 ? framecount + 1 : 0;
    if(laser)
    lasery -= 6;
    if(lasery < 0)
    laser = false;
    private void setDX(int i, int ai[], int j)
    if(i == -1)
    for(int k = 0; k < slen; k++)
    if(!flying[k])
    dx[k] = ai;
    dxcount[k] = 0;
    pmode[k] = j;
    } else
    dx[i] = ai;
    dxcount[i] = 0;
    pmode[i] = j;
    private void setDY(int i, int ai[], int j)
    if(i == -1)
    for(int k = 0; k < slen; k++)
    if(!flying[k])
    dy[k] = ai;
    dycount[k] = 0;
    pmode[k] = j;
    } else
    dy[i] = ai;
    dycount[i] = 0;
    pmode[i] = j;
    private void changePackDir(int ai[], int ai1[])
    setDX(-1, ai, 0);
    setDY(-1, ai1, 0);
    packdx = ai;
    packdy = ai1;
    packcount = 0;
    private void updatePlayerPos(int i)
    plastx = px;
    px += i;
    if(px + pedgeH > WIDTH || px - pedgeH < 0)
    px = plastx;
    private void fireLaser()
    if(!laser)
    laser = true;
    laserx = px;
    lasery = py;
    private void alienHit(int i)
    if(!playerdead)
    dead[i] = true;
    laser = false;
    killed++;
    if(flying[i])
    score += 200;
    else
    score += 50;
    if(killed == slen)
    waveComplete();
    scorestr = getScoreStr(score);
    private void playerHit()
    playerdead = true;
    playerpause = 0;
    explodeframe = 0;
    lives--;
    if(lives == 0)
    gameOver();
    private void waveComplete()
    wavecomplete = true;
    difficulty -= 100;
    if(difficulty < 100)
    difficulty = 100;
    msg = "WAVE " + wave + " COMPLETE";
    messagepause = 0;
    showmessage = true;
    wave++;
    score += 1000 * wave;
    scorestr = getScoreStr(score);
    private void gameOver()
    gameover = true;
    msg = "GAME OVER";
    for(int i = 0; i < 5; i++)
    if(score < highscore[i])
    continue;
    for(int j = 4; j > i; j--)
    highscore[j] = highscore[j - 1];
    highscore[i] = score;
    rank = i;
    break;
    setHighScores();
    showmessage = true;
    messagepause = 0;
    addEndCommands(mainscreen, true);
    private void addBeginCommands(Displayable displayable, boolean flag)
    if(flag)
    removeCommands();
    displayable.addCommand(playCommand);
    displayable.addCommand(exitCommand);
    displayable.setCommandListener(this);
    private void addPlayCommands(Displayable displayable, boolean flag)
    if(flag)
    removeCommands();
    displayable.addCommand(nullCommand);
    displayable.addCommand(quitCommand);
    displayable.setCommandListener(this);
    private void addEndCommands(Displayable displayable, boolean flag)
    if(flag)
    removeCommands();
    displayable.addCommand(againCommand);
    displayable.addCommand(quitCommand);
    displayable.setCommandListener(this);
    private void removeCommands()
    Displayable displayable = display.getCurrent();
    displayable.removeCommand(nullCommand);
    displayable.removeCommand(quitCommand);
    displayable.removeCommand(againCommand);
    displayable.removeCommand(playCommand);
    displayable.removeCommand(exitCommand);
    public void commandAction(Command command, Displayable displayable)
    if(command == playCommand)
    display.setCurrent(mainscreen);
    startGame();
    if(command == quitCommand)
    runner = false;
    while(th.isAlive()) ;
    th = null;
    addPlayCommands(mainscreen, true);
    display.setCurrent(titlescreen);
    if(command == againCommand)
    runner = false;
    while(th.isAlive()) ;
    th = null;
    display.setCurrent(mainscreen);
    addPlayCommands(mainscreen, true);
    startGame();
    if(command == exitCommand)
    destroyApp(false);
    notifyDestroyed();
    private int[] getHighScores()
    int ai[] = new int[5];
    ai[0] = 5000;
    ai[1] = 4000;
    ai[2] = 3000;
    ai[3] = 2000;
    ai[4] = 1000;
    byte abyte0[][] = new byte[5][6];
    try
    hsdata = RecordStore.openRecordStore("MobileGalaga", true);
    int i = hsdata.getNumRecords();
    if(i == 0)
    for(int j = 0; j < 5; j++)
    abyte0[j] = Integer.toString(ai[j]).getBytes();
    hsdata.addRecord(abyte0[j], 0, abyte0[j].length);
    } else
    for(int k = 0; k < 5; k++)
    abyte0[k] = hsdata.getRecord(k + 1);
    String s = "";
    for(int l = 0; l < abyte0[k].length; l++)
    s = s + (char)abyte0[k][l] + "";
    ai[k] = Integer.parseInt(s);
    catch(RecordStoreException recordstoreexception)
    db("problem with initialising highscore data\n" + recordstoreexception);
    return ai;
    private void setHighScores()
    byte abyte0[][] = new byte[5][6];
    try
    hsdata = RecordStore.openRecordStore("MobileGalaga", true);
    for(int i = 0; i < 5; i++)
    abyte0[i] = Integer.toString(highscore[i]).getBytes();
    hsdata.setRecord(i + 1, abyte0[i], 0, abyte0[i].length);
    catch(RecordStoreException recordstoreexception)
    db("problem with setting highscore data\n" + recordstoreexception);
    private String getScoreStr(int i)
    templen = 6 - (i + "").length();
    tempstr = "";
    for(int j = 0; j < templen; j++)
    tempstr = tempstr + "0";
    return tempstr + i;
    public static void db(String s)
    System.out.println(s);
    public static void db(int i)
    System.out.println(i + "");
    private Display display;
    private Command exitCommand;
    private Command playCommand;
    private Command quitCommand;
    private Command againCommand;
    private Command nullCommand;
    private MainScreen mainscreen;
    private TitleScreen titlescreen;
    private ScoreScreen scorescreen;
    private static int WIDTH;
    private static int HEIGHT;
    private static int CENTERW;
    private static int CENTERH;
    private boolean runner;
    private Thread th;
    private Random rand;
    private static final int RED = 0xff0000;
    private static final int ORANGE = 0xff9100;
    private static final int YELLOW = 0xffff00;
    private static final int WHITE = 0xffffff;
    private static final int BLACK = 0;
    private static final int BLUE = 0x160291;
    private static Image alienimg[] = new Image[2];
    private static Image explosionimg[] = new Image[3];
    private static Image playerimg;
    private static Image logoimg;
    private static int imgH;
    private static int imgW;
    private static int pimgH;
    private static int pimgW;
    private static int edgeH;
    private static int edgeV;
    private static int pedgeH;
    private static int pedgeV;
    private static final Font fs = Font.getFont(64, 0, 8);
    private static final Font fl = Font.getFont(64, 1, 16);
    private static final int sposX[] = {
    16, 28, 40, 52, 4, 16, 28, 40, 52, 64,
    4, 16, 28, 40, 52, 64
    private static final int sposY[] = {
    14, 14, 14, 14, 26, 26, 26, 26, 26, 26,
    38, 38, 38, 38, 38, 38
    private static final int LOOP = 0;
    private static final int ONCE = 1;
    private static final int HOLD = 2;
    private static final int move_none[] = {
    0
    private static final int alien_dx_right[] = {
    1, 1, 1, 1, 1, 1, 1, 1
    private static final int alien_dy_right[] = {
    0, 0, 1, 1, 0, 0, -1, -1
    private static final int alien_dx_left[] = {
    -1, -1, -1, -1, -1, -1, -1, -1
    private static final int alien_dy_left[] = {
    0, 0, -1, -1, 0, 0, 1, 1
    private static final int alien_dx_flyright[] = {
    1, 1, 1, 0, -1, -1, -1, -1, -1, 0,
    1, 1, 2, 3, 4, 5, 6
    private static final int alien_dy_flyright[] = {
    0, -1, -1, -1, -1, -1, 0, 1, 1, 1,
    1, 1, 2, 3, 4, 5, 6
    private static final int alien_dx_flyleft[] = {
    -1, -1, -1, 0, 1, 1, 1, 1, 1, 0,
    -1, -1, -2, -3, -4, -5, -6
    private static final int alien_dy_flyleft[] = {
    0, -1, -1, -1, -1, -1, 0, 1, 1, 1,
    1, 1, 2, 3, 4, 5, 6
    private static final int slen;
    private static final int ailen;
    private static final int packlen;
    private static int pmode[];
    private static int x[];
    private static int y[];
    private static int dx[][];
    private static int dy[][];
    private static int dxcount[];
    private static int dycount[];
    private static int frame[];
    private static boolean flying[];
    private static boolean dead[];
    private static boolean exploding[];
    private static int lastx;
    private static int lasty;
    private static int fly;
    private static int packX[];
    private static int packY[];
    private static int packdx[];
    private static int packdy[];
    private static int packcount;
    private static int framecount = 3;
    private static int px;
    private static int py;
    private static int plastx;
    private static int score;
    private static String scorestr;
    private static int lives;
    private static int killed;
    private static boolean playerdead;
    private static int explodeframe;
    private static int playerpause;
    private static int rank;
    private static boolean playerLeft;
    private static boolean playerRight;
    private static boolean laser;
    private static int laserx;
    private static int lasery;
    private static RecordStore hsdata;
    private static int highscore[] = new int[5];
    private static boolean showmessage;
    private static boolean showscores;
    private static boolean gameover;
    private static boolean wavecomplete;
    private static int messagepause;
    private static String msg;
    private static int difficulty;
    private static int wave;
    private static String tempstr;
    private static int templen;
    static
    slen = sposX.length;
    ailen = alien_dx_flyright.length;
    packlen = alien_dx_right.length;
    pmode = new int[slen];
    x = new int[slen];
    y = new int[slen];
    dx = new int[slen][ailen];
    dy = new int[slen][ailen];
    dxcount = new int[slen];
    dycount = new int[slen];
    frame = new int[slen];
    flying = new boolean[slen];
    dead = new boolean[slen];
    exploding = new boolean[slen];
    packX = new int[slen];
    packY = new int[slen];
    packdx = new int[packlen];
    packdy = new int[packlen];
    ----END OF CODE ----------------

    hi sorry if it's too big! i hope i can explain this very well (you know i only got this code in the net), if you try to run the program in emulator, the and lunch it will it will first display the title screen and if you hit the pressed key 5 it will display help,
    so my problem is how to move UP and DOWN and also if i pressed the fire button it will continue to fire. here is the code.
    //Code for the Left,Right,UP and Down movement and also the fire
    public void keyPressed(int i)
    int j = getGameAction(i);
    if(j == 2)
    MobileGalaga.playerLeft = true; //this is ok
    else
    if(j == 5)
    MobileGalaga.playerRight = true; //this is ok
    else
    if(j==1)
    MobileGalaga.playerUp = true; //i add this only, this has a problem
    else
    if(j==6)
    MobileGalaga.playerDown = true; //i add this only, this has a problem
    else
    if(j == 8)
    fireLaser(); //for the release of fire
    //for the release of key pressed
    public void keyReleased(int i)
    int j = getGameAction(i);
    if(j == 2)
    MobileGalaga.playerLeft = false;
    else
    if(j == 5)
    MobileGalaga.playerRight = false;
    //Update the position base on key pressed
    private void updatePos()
    if(playerLeft)
    updatePlayerPos(-5);
    else
    if(playerUp)
    updatePlayerPos1(-4);
    else
    if(playerDown)
    updatePlayerPos1(4);
    else
    if(playerRight)
    updatePlayerPos(5);
    fly = Math.abs(rand.nextInt() % difficulty);
    if(fly < slen && !flying[fly] && !dead[fly])
    if(x[fly] < CENTERW)
    setDX(fly, alien_dx_flyright, 2);
    setDY(fly, alien_dy_flyright, 2);
    } else
    setDX(fly, alien_dx_flyleft, 2);
    setDY(fly, alien_dy_flyleft, 2);
    flying[fly] = true;
    for(int i = 0; i < slen; i++)
    if(!dead)
    if(!flying[i])
    if(x[i] + edgeH + dx[i][dxcount[i]] > WIDTH)
    changePackDir(alien_dx_left, alien_dy_left);
    if((x[i] - edgeH) + dx[i][dxcount[i]] < 0)
    changePackDir(alien_dx_right, alien_dy_right);
    } else
    if(y[i] + edgeV + dy[i][dycount[i]] > HEIGHT)
    x[i] = packX[i];
    y[i] = packY[i];
    flying[i] = false;
    setDX(i, packdx, 0);
    setDY(i, packdy, 0);
    if(!playerdead && y[i] <= py + pedgeV && y[i] >= py - pedgeV && x[i] <= px + pedgeH && x[i] >= px - pedgeH)
    playerHit();
    if(laser && lasery <= y[i] + edgeV && lasery >= y[i] - edgeV && laserx <= x[i] + edgeH && laserx >= x[i] - edgeH)
    alienHit(i);
    for(int j = 0; j < slen; j++)
    if(!dead[j])
    if(framecount == 3)
    frame[j] = frame[j] + 1 < 2 ? 1 : 0;
    lastx = x[j];
    lasty = y[j];
    x[j] += dx[j][dxcount[j]];
    y[j] += dy[j][dycount[j]];
    if(pmode[j] == 0)
    dxcount[j] = dxcount[j] + 1 < dx[j].length ? dxcount[j] + 1 : 0;
    dycount[j] = dycount[j] + 1 < dy[j].length ? dycount[j] + 1 : 0;
    } else
    if(pmode[j] == 2)
    dxcount[j] = dxcount[j] + 1 < dx[j].length ? dxcount[j] + 1 : dxcount[j];
    dycount[j] = dycount[j] + 1 < dy[j].length ? dycount[j] + 1 : dycount[j];
    packX[j] += packdx[packcount];
    packY[j] += packdy[packcount];
    packcount = packcount + 1 < packlen ? packcount + 1 : 0;
    framecount = framecount + 1 < 4 ? framecount + 1 : 0;
    if(laser)
    lasery -= 6;
    if(lasery < 0 )
    laser = false;
    // this will move the object UP,DOWN,Left and Right
    private void updatePlayerPos(int i)
    plastx = px;
    px += i;
    if(px + pedgeH > WIDTH || px - pedgeH < 0)
    px = plastx;
    private void updatePlayerPos1(int i)
    plastx = py;
    py += i;
    if(px + pedgeV > HEIGHT || px - pedgeV < 0)
    px = plastx;
    // This will fire, if you hit the fire button
    private void fireLaser()
    if(!laser)
    laser = true;
    laserx = px;
    lasery = py;
    sorry if it's too long i just want too explain this. if anyone like to see this and run so that you can see it also, i can send an email.
    thanks,
    alek

  • Help displaying an image using the canvas!!!!!!!!

    Hey guys
    I don't know whether I am not grasping some concepts well.I have been going mad trying to get the code working
    Here is the code
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    * @author Administrator
    * @version
    public class MyMIDlet extends javax.microedition.midlet.MIDlet implements CommandListener{
    private Display display;
    private MyCanvas canvas;
    private Command exitcommand = new Command("Exit",Command.SCREEN,1);
    private Image source;
    public MyMIDlet() {
    protected void startApp() throws MIDletStateChangeException{
    if (display == null){
    initMIDlet();
    protected void pauseApp() {
    protected void destroyApp(boolean unconditional)throws MIDletStateChangeException {
    exitMIDlet();
    public void commandAction(Command c, Displayable d) {
    if (c == exitcommand){
    exitMIDlet();
    protected void initMIDlet() {
    display = Display.getDisplay(this);
    canvas = new MyCanvas(this);
    System.err.println("Canvas instiated succesfully");
    canvas.addCommand(exitcommand);
    canvas.setCommandListener(this);
    display.setCurrent(canvas);
    public void exitMIDlet() {
    notifyDestroyed();
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import java.io.*;
    public class MyCanvas extends Canvas implements Runnable {
    private MIDlet midlet;
    private Image offscreen;
    private Image currentimage;
    private Graphics g;
    //MID profile application
    /** Creates a new instance of MyCanvas */
    public MyCanvas(MIDlet midlet) {
    this.midlet = midlet;
    try{
    currentimage = Image.createImage("/bird0.png");
    }catch(IOException e){
    System.err.println(e.getMessage());
    if (currentimage!= null){
    System.err.println("Image create successfully");
    }else{
    System.err.println("Image not created");
    try{
    Thread t = new Thread(this);
    t.start();
    }catch(Execption e){}
    protected void paint(Graphics g){
    Graphics saved = g;
    int x = getWidth();
    int y = getHeight();
    g.setColor(255,255,255);
    g.drawImage(currentimage,x,y,g.TOP|g.VCENTER);
    public void run() {
    repaint();
    I know for a fact that the Canvas class 's paint method is called by the system and not the application. This poses a problem for me because I am not sure how to pass the image to the piant method, so that it can be painted.
    When I run the program(using J2ME wtk04), this is the outcome.
    Image created succesfully
    Canvas instiatiated successfully
    null
    Here are my questions
    1) when is the paint method precisely called by the system?after a reference to the canvas class is created?
    2) is it wise to create the image when instiating the canvas class?( initially created the image using a separate thread)-when sould the image be created?
    3)how to let the application know when to use the image when painting the display area?
    I am just trying the logistics here. It is very crucial to me to understand the bolts of this as the core f my project fouses on the man machine interface development.(For the project, the cilent application is quering for the map using HTTP)
    I use a png file of size 161 bytes. Is that too big for testing purposes.
    I would all the help that I can get. thanks in advance

    1) when is the paint method precisely called by the system?after a reference to the canvas class is created?
    After the canvas is set as the current display, and after that, after the repaint() is called.
    2) is it wise to create the image when instiating the canvas class?( initially created the image using a separate thread)-when sould the image be created?
    It's better to create the image in the very begining of the program e.g. in the midlet initialization. You can call the created image as often as you like later on
    3)how to let the application know when to use the image when painting the display area?
    you have to tell it :))
    you can use if-then, switch, or anything else
    and you can use clipping too

  • [Request For Help] How To Send Email Midlet Using Secure Socket ?

    Hello, this is the first time i ask for help to forum.sun.com.
    i try to make secure connection for send email from MIDlet. Maybe you can check to my code :
    EmailMidlet.java
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.lcdui.;
    public class EmailMidlet extends MIDlet implements CommandListener{
    Display display = null;
    // email form fields
    TextField toField = null;
    TextField subjectField = null;
    TextField msgField = null;
    Form form;
    static final Command sendCommand = new Command("send", Command.OK, 2);
    static final Command clearCommand = new Command("clear", Command.STOP, 3);
    String to;
    String subject;
    String msg;
    public EmailMidlet() {
    display = Display.getDisplay(this);
    form = new Form("Compose Message");
    toField = new TextField("To:", "", 50, TextField.EMAILADDR);
    subjectField = new TextField("Subject:", "", 15, TextField.ANY);
    msgField = new TextField("MsgBody:", "", 90, TextField.ANY);
    public void startApp() throws MIDletStateChangeException {
    form.append(toField);
    form.append(subjectField);
    form.append(msgField);
    form.addCommand(clearCommand);
    form.addCommand(sendCommand);
    form.setCommandListener(this);
    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("clear")) {
    destroyApp(true);
    } else if (label.equals("send")) {
    to = toField.getString();
    subject = subjectField.getString();
    msg = msgField.getString();
    EmailClient client = new EmailClient(this,"[email protected]", to, subject, msg);
    client.start();
    }and EmailClient.java
    import javax.microedition.io.;
    import javax.microedition.lcdui.;
    import java.io.;
    import java.util.Date;
    public class EmailClient implements Runnable {
    private EmailMidlet parent;
    private Display display;
    private Form f;
    private StringItem si;
    private SecureConnection sc; //SSL
    private InputStream is;
    private OutputStream os;
    private String smtpServerAddress = "smtp.gmail.com"; //SSL
    String from;
    String to;
    String subject;
    String msg;
    public EmailClient(EmailMidlet m, String from, String to, String subject, String msg) {
    parent = m;
    this.from = from;
    this.to = to;
    this.subject = subject;
    this.msg = msg;
    display = Display.getDisplay(parent);
    f = new Form("Email Client");
    si = new StringItem("Response:" , " ");
    f.append(si);
    display.setCurrent(f);
    public void start() {
    Thread t = new Thread(this);
    t.start();
    public void run() {
    try {
    //SSL
    sc = (SecureConnection)
    Connector.open("ssl://"smtpServerAddress":465"); //smtp with SSL port 465
    sc.setSocketOption(SocketConnection.LINGER, 5);
    is = sc.openInputStream();
    os = sc.openOutputStream();
    os.write(("HELO there" "\r\n").getBytes());
    os.write(("EHLO" "\r\n").getBytes());
    os.write(("auth login" "\r\n").getBytes());
    os.write(("dHVnYXNha2hpci50cmlhZGl0eWFAZ21haWwuY29t" "\r\n").getBytes());
    os.write(("dGEuZW1haWxjbGllbnQ=" "\r\n").getBytes());
    os.write(("MAIL FROM:<">\r\n").getBytes());
    os.write(("RCPT TO:<">\r\n").getBytes());
    os.write("DATA\r\n".getBytes());
    // stamp the msg with date
    os.write(("Date: " new Date() "\r\n").getBytes());
    os.write(("From: "+from"\r\n").getBytes());
    os.write(("To: "to"\r\n").getBytes());
    os.write(("Subject: "subject"\r\n").getBytes());
    os.write((msg+"\r\n").getBytes()); // message body
    os.write(".\r\n".getBytes());
    os.write("QUIT\r\n".getBytes());
    StringBuffer sb = new StringBuffer();
    int ch = 0;
    while((ch = is.read()) != -1) {
    sb.append((char) ch);
    si.setText("SMTP server response - " + sb.toString());
    } catch(IOException e) {
    e.printStackTrace();
    Alert a = new Alert
    ("TimeClient", "Cannot connect to SMTP server. Ping the server to make sure it is running...", null, AlertType.ERROR);
    a.setTimeout(Alert.FOREVER);
    display.setCurrent(a);
    } finally {
    try {
    if(is != null) {
    is.close();
    if(os != null) {
    os.close();
    if(sc != null) {
    sc.close();
    } catch(IOException e) {
    e.printStackTrace();
    public void commandAction(Command c, Displayable s) {
    if (c == Alert.DISMISS_COMMAND) {
    parent.notifyDestroyed();
    parent.destroyApp(true);
    } When I try to debug project from netbeans, i found this error :
    Starting emulator in debug server mode on port 2668
    Connecting to 127.0.0.1 on port 2800
    nbdebug:
    Waiting for debugger on port 2668
    Waiting for KVM...
    Running with storage root temp.SonyEricsson_JP8_128x160_Emu10
    KdpDebugTask connecting to debugger 1 ..
    Running with locale: Indonesian_Indonesia.1252
    Connected to KVM
    Connection received.
    Attached JPDA debugger to localhost:2668
    java.io.IOException: error 10054 during TCP read +
    at com.sun.midp.io.j2me.socket.Protocol.nonBufferedRead(Protocol.java:299)+
    at com.sun.midp.io.BufferedConnectionAdapter.readBytes(BufferedConnectionAdapter.java:99)+
    at com.sun.midp.io.BaseInputStream.read(ConnectionBaseAdapter.java:582)+
    at com.sun.midp.ssl.Record.rdRec(+41)+
    at com.sun.midp.ssl.Record.rdRec(+5)+
    at com.sun.midp.ssl.In.refill(+18)+
    at com.sun.midp.ssl.In.read(+29)+
    at EmailClient.run(EmailClient.java:74)+
    Execution completed.
    5145824 bytecodes executed
    9258 thread switches
    1762 classes in the system (including system classes)
    0 dynamic objects allocated (0 bytes)
    0 garbage collections (0 bytes collected)
    debug:
    BUILD SUCCESSFUL (total time: 4 minutes 34 seconds)
    Regard
    Littlebro

    Don't multipost and don't use the browser's back button to edit your posts as that creates multiple postings. I've removed the other thread you started with the same questio.
    Also, don't post to long dead threads. I've blocked your post and locked the thread you resurrected.
    db

  • Command or Canvas Events for Recording ?? Please Help..

    Hi I am Abhijith I am a total newbie to the j2me world, And I am learning it now,
    My project topic is "Bluetooth Walkie Talkie " , And I am trying my best and putting
    all my efforts to code incrementally by learning , Before I could implement bluetooth,
    I thought let me complete the recording The audio and playing part first,
    The recording and playing of audio is working fine , But i would like to do it a real manner as Real Walkie talkie does, I want to record audio ONLY when the Key is being
    pressed , and when its released it should exit the player hence saving the recorded file,
    (Actually i dont want to save it in future,i would be sending the bytearray though the bluetooth , but for now , I want the Current module to be ready)
    I tried my best searching online to implement my requirement but the couldnot find
    such events I found Canva's KEYPRESS, KEYRELEASE , etc events but they dint not
    serve my purpose, Let me clearly tell where I am stuck , After the midlet starts(by launching it) then i would like to press a key( keypressed say No 5) for certain
    amount of time and the audio should be recorded only for the keypressed duration ,
    after I release , it should stop recording and save as a wav file .
    Whats happening is When i keep the key pressed , The midlet asks whether to allow
    the recording , for this purpose when I release key the control is going out, and
    i am not able to achieve the needed , I am posting the code here, Please Help me.
    I am not asking for the complete spoon feeding or ready made code, But as a beginner
    I need help from you all to learn and implement it.(at least it should satisfy me,i would feel i have learnt something then)
    Here below is my code ( i AM using WTK 2.5 )
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import java.io.*;
    import javax.microedition.media.control.*;
    import java.util.*;
    import javax.microedition.io.*;
    import javax.microedition.io.file.*;
    public class Key extends MIDlet{
      private Display  display;
      private KeyCodeCanvas canvas;
      public Key(){
        display = Display.getDisplay(this);
        canvas  = new KeyCodeCanvas(this);
      protected void startApp(){
        display.setCurrent(canvas);
      protected void pauseApp(){}
      protected void destroyApp( boolean unconditional ){
        notifyDestroyed();
    class KeyCodeCanvas extends Canvas implements CommandListener{
      private Command exit;
         public StringItem message ;
         private Player player;
         private byte[] recordedAudioArray = null;
      private String keyValue = null;
      private Key midlet;
         Thread t = null;
         private String eventType = null;
      public KeyCodeCanvas(Key midlet){
        this.midlet = midlet;
        exit = new Command("Exit", Command.EXIT, 1);
        addCommand(exit);
        setCommandListener(this);
      protected void paint(Graphics g){
          g.setColor(255, 0, 0);
          g.fillRect(0, 0, getWidth(), getHeight());
        if (keyValue != null){
          g.setColor(0, 0, 255);
           g.drawString(keyValue + eventType+message, getWidth() / 2, getHeight() / 2,
         Graphics.TOP | Graphics.HCENTER);
      public void commandAction(Command c, Displayable d){
        String label = c.getLabel();
        if(label.equals("Exit"))
          midlet.destroyApp(true);
      protected void keyPressed(int keyCode){
         eventType = "pressed";
        keyValue = getKeyName(keyCode);
        repaint();
      public void keyReleased(int keyCode)
           try
                eventType = "released";
                keyValue = getKeyName(keyCode);
                repaint();
           catch (Exception e)
                System.out.print(e);
      public void keyRepeated(int keyCode)
           eventType = "repeated";
           keyValue = getKeyName(keyCode);
           try
                Thread t1 = new Thread()
                     public void run()
                          try
                               player = Manager.createPlayer("capture://audio?encoding=pcm");
                               player.realize();
                               RecordControl rc = (RecordControl)player.getControl("RecordControl");
                               ByteArrayOutputStream output = new ByteArrayOutputStream();
                               rc.setRecordStream(output);
                               rc.startRecord();
                               player.start();
                               eventType = "Recording";
                               message.setText("Recording...");
                               Thread.sleep(5000);
                               message.setText("Recording Done!");
                               rc.commit();
                               recordedAudioArray = output.toByteArray();
                               player.close();
                          catch (Exception e)
                }; t1.start();
           catch (Exception e)
           repaint();
         //Runnable r1 = new Runnable()
         //    public void run()
         //        try
         //            System.out.print(" here 1");
         //            message.setText(" here 1 ");
         //            player = Manager.createPlayer("capture://audio?encoding=pcm");
         //            player.realize();
         //            RecordControl rc = (RecordControl)player.getControl("RecordControl");
         //            ByteArrayOutputStream output = new ByteArrayOutputStream();
         //            rc.setRecordStream(output);
         //            rc.startRecord();
         //            player.start();
         //            eventType = "Recording";
         //            message.setText("Recording...");
         //            Thread.sleep(5000);
         //            message.setText("Recording Done!");
         //            rc.commit();
         //            recordedAudioArray = output.toByteArray();
         //            player.close();
         //        catch (Exception e)
    }I am really sorry at the end I messed with the code and its altered a Lot, But hope the
    logic Will is clear which is my requirement . I know the code for recording and
    playing is not complete as said, i Messed around a working code and tried adding Canavs
    for keyrepeat method,tried putting a thread around , AT last totally messed,
    I tried working on this for two days but couldn't be successfull , Please Help me!!
    The control goes out when midlet asks whether to allow recording ,
    I thank you anticipation ...
    -Abhijith Rao

    Midlet asking whether to allow the recording are typical permissions prompts specified by MIDP security policy. You need to sign the MIDlet and give it proper permissions.
    Problems like this were discussed in an older thread at WTK forum: *[MIDlet keeps asking for permission.|http://forums.sun.com/thread.jspa?threadID=5347313]* According to one of the posters in the thread, +"...I got it to work on the emulator by setting the permission to 'manufacturer'. It runs smoothly without annoying questions..."+
    If you're interested, check documentation and tutorials on MIDP security policy for more details.
    For events to record audio only when the key is being pressed, consider GameCanvas API, method getKeyStates.
    I am not certain though if doing it this way is a good idea. I doubt that phone users have same habits as those of walkie-talkies; for them it might be indeed more comfortable to use single simple key presses to start and finish recording.

  • Java 3D help me !

    I cannt build this source by jbuilder . Pls help me, it show this error , thanks alot
    C:\WTK22\bin\preverify.exe -cldc -classpath "D:\mobile3d\M3G\classes;C:\WTK22\lib\mmapi.jar;C:\WTK22\lib\wma20.jar;C:\WTK22\lib\j2me-ws.jar;C:\WTK22\lib\jsr75.jar;C:\WTK22\lib\jsr082.jar;C:\WTK22\lib\jsr184.jar;C:\WTK22\lib\cldcapi11.jar;C:\WTK22\lib\midpapi20.jar;C:\WTK22\lib\cldcapi10.jar;C:\WTK22\lib\midpapi10.jar;C:\WTK22\lib\wma11.jar" -d "D:\mobile3d\M3G\preverified-classes" @"D:\mobile3d\M3G\preverified-classes\params"
    ERROR: floating-point constants should not appear
    Error preverifying class m3g.HandCanvas
    ------------------------------- SOURCE WITH 3 CLASS ------------------------
    class 1 :
    // HandDisplay.java
    // Andrew Davison, [email protected], July 2004
    /* Display a 3D model loaded as a series of coordinates.
    The model can be moved and rotated around the y-axis.
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class HandDisplay extends MIDlet
    public void startApp()
    { Display d = Display.getDisplay(this);
    d.setCurrent( new HandCanvas(this) );
    public void pauseApp() {}
    public void destroyApp(boolean unconditional) {}
    public void quitApp()
    { notifyDestroyed(); }
    } // end of HandDisplay class
    ---- class 2 --------------------------------------------------------------------------------------------------------------------------------------------------------
    // HandCanvas.java
    // Andrew Davison, [email protected], July 2004
    /* Display a 3D model.
    The model can be moved left, right, up, down, forward, and back,
    and rotated left/right around the y-axis.
    Holding a key down causing key repetition, even in implementations
    which don't support keyRepeated().
    The model-specific data is located in the methods:
    getVerts() : returns its vertices
    getNormals() : returns its normals
    getTexCoords() : returns its texture coordinates
    getStripLengths() : returns an array containing the lengths of each
    of the triangle strips in the shape
    setMatColours() : sets the material colours and shininess
    getColourCoords(): returns its colour coordinates
    These methods are generated by the ObjView Java 3D application; they
    can be copied over from the examObj.txt file that ObjView outputs.
    The texture image filename should be placed in the TEX_FNM constant.
    The camera's position may need to be adjusted, by changing the
    X_CAMERA, Y_CAMERA, Z_CAMERA values.
    import javax.microedition.lcdui.*;
    import javax.microedition.m3g.*;
    public class HandCanvas extends Canvas
    implements CommandListener
    private static final String TEX_FNM = "/r.gif";
    // name of tex image file; change as required
    private static final float X_CAMERA = 0.0f;
    private static final float Y_CAMERA = 0.0f;
    private static final float Z_CAMERA = 3.0f;
    // camera coordinates; change as required
    private static final float MODEL_MOVE = 0.2f;
    // distance to move the model up/down/left/right/fwd/back for a key press
    private static final float MODEL_ROT = 5.0f; // 5 degrees
    // angle to rotate the model left/right for a key press
    private HandDisplay top;
    private Graphics3D g3d;
    private Camera camera;
    private Light light;
    private Background bg;
    private VertexBuffer vertBuf;
    // holds the model's positions, normals, colors coords, and tex coords
    private IndexBuffer idxBuf;
    // indices to the model's triangle strips
    private Appearance app;
    private Transform camTrans, modelTrans;
    // transforms used by the camera and the model
    // model position and angle information
    private float xTrans, yTrans, zTrans;
    private int totalDegrees;
    private KeyRepeat keyRepeater; // for repeating key presses
    public HandCanvas(HandDisplay top)
    this.top = top;
    setCommandListener(this);
    keyRepeater = new KeyRepeat(this);
    keyRepeater.start();
    try {
    createScene();
    catch (Exception e)
    { e.printStackTrace(); }
    } // end of HandCanvas()
    public void commandAction(Command c, Displayable d)
    if (c.getCommandType() == Command.EXIT) {
    keyRepeater.cancel();
    keyRepeater = null;
    top.quitApp();
    } // end of commandAction()
    private void createScene() throws Exception
    addCommand( new Command("Exit", Command.EXIT, 1) );
    g3d = Graphics3D.getInstance();
    // create a camera
    camera = new Camera();
    float aspectRatio = ((float) getWidth()) / ((float) getHeight());
    camera.setPerspective(45.0f, aspectRatio, 0.1f, 50.0f);
    // was 60, aspectRatio, 1, 1000
    // set up the camera's position
    camTrans = new Transform();
    camTrans.postTranslate(X_CAMERA, Y_CAMERA, Z_CAMERA);
    // create a light
    light = new Light();
    light.setColor(0xffffff); // white light
    light.setIntensity(1.25f); // over bright
    // initialise the model's transform vars
    modelTrans = new Transform();
    xTrans = 0.0f; yTrans = 0.0f; zTrans = 0.0f;
    totalDegrees = 0;
    makeGeometry();
    makeAppearance();
    bg = new Background();
    bg.setColor(0x9EFEFE); // light blue
    } // end of createScene()
    // ------------------- model creation -----------------------------
    private void makeGeometry()
    /* Read in the values for the vertices, normals, texture coords,
    and colour coords, and create a VertexBuffer object. Also
    read in the strip lengths array to create the index for the
    triangle strips used in the vertex buffer.
    Depending on the model, there may not be any texture or colour
    coordinates, and so the calls related to them should be commented
    out.
    The texture coordinates can use 2, 3, or 4 components, and the
    colour coordinates 3 or 4, which will require changes to the array
    creation code. The code here assumes (s,t) format for texture coords
    (2 components) and RGB for the colours (3 components), the most common
    formats.
    // create vertices
    short[] verts = getVerts();
    VertexArray va = new VertexArray(verts.length/3, 3, 2);
    va.set(0, verts.length/3, verts);
    // create normals
    byte[] norms = getNormals();
    VertexArray normArray = new VertexArray(norms.length/3, 3, 1);
    normArray.set(0, norms.length/3, norms);
    // create texture coordinates
    short[] tcs = getTexCoordsRev();
    VertexArray texArray = new VertexArray(tcs.length/2, 2, 2);
    // this assumes (s,t) texture coordinates
    texArray.set(0, tcs.length/2, tcs);
    // create colour coordinates
    short[] cols = getColourCoords();
    VertexArray colsArray = new VertexArray(cols.length/3, 3, 2);
    // this assumes RGB colour coordinates
    colsArray.set(0, cols.length/3, cols);
    // ------ create the VertexBuffer for the model -------
    vertBuf = new VertexBuffer();
    float[] pbias = {(1.0f/255.0f), (1.0f/255.0f), (1.0f/255.0f)};
    vertBuf.setPositions(va, (2.0f/255.0f), pbias); // scale, bias
    // fix the scale and bias to create points in range [-1 to 1]
    vertBuf.setNormals(normArray);
    // vertBuf.setTexCoords(0, texArray, (1.0f/255.0f), null);
    // fix the scale to create texCoords in range [0 to 1]
    // vertBuf.setColors(colsArray);
    // create the index buffer for the model (this tells MIDP how to
    // create triangle strips from the contents of the vertex buffer).
    idxBuf = new TriangleStripArray(0, getStripLengths() );
    } // end of makeGeometry()
    private short[] getTexCoordsRev()
    // Return an array of texture coords (s,t)
    // with their t coords reversed.
    // This method will need to be commented out if there are
    // no textures used in the model.
    short[] tcs = getTexCoords();
    // t' = 255 - t (will later be scaled from 255 to 1)
    for(int i=1; i < tcs.length; i=i+2)
    tcs = (short)(255 - tcs);
    return tcs;
    } // end of getTexCoordsRev()
    private void makeAppearance() throws Exception
    /* Load the texture and material information into the Appearance
    node.
    Depending on the model, there may not be a texture image, and so
    the texture-specific code here will need to be commented out.
    The material colour and shininess data is obtained from
    setMatColours().
    // load the image for the texture
    Image im = Image.createImage(TEX_FNM);
    // create an Image2D for the Texture2D
    Image2D image2D = new Image2D(Image2D.RGB, im);
    // create the Texture2D and enable mip mapping
    // the texture color is modulated with the lit material color
    Texture2D tex = new Texture2D(image2D);
    tex.setFiltering(Texture2D.FILTER_NEAREST, Texture2D.FILTER_NEAREST);
    tex.setWrapping(Texture2D.WRAP_CLAMP, Texture2D.WRAP_CLAMP);
    // tex.setWrapping(Texture2D.WRAP_REPEAT, Texture2D.WRAP_REPEAT);
    tex.setBlending(Texture2D.FUNC_MODULATE);
    // create the appearance
    app = new Appearance();
    // app.setTexture(0, tex);
    app.setMaterial( setMatColours() );
    } // end of makeAppearance()
    // ------------------ paint the canvas ------------------
    public void paint(Graphics g)
    // bind the canvas graphic to our Graphics3D object
    g3d.bindTarget(g, true, Graphics3D.DITHER | Graphics3D.TRUE_COLOR);
    g3d.clear(bg); // clear the color and depth buffers
    g3d.setCamera(camera, camTrans); // position the camera
    // set up a "headlight": a directional light shining
    // from the direction of the camera
    g3d.resetLights();
    g3d.addLight(light, camTrans);
    updateModelTrans();
    // Render the model. We provide the vertex and index buffers
    // to specify the geometry; the appearance so we know what
    // material and texture to use; and a tranform to position
    // the model
    g3d.render(vertBuf, idxBuf, app, modelTrans);
    g3d.releaseTarget(); // flush
    } // end of paint()
    private void updateModelTrans()
    // the model's transform = a translation * a rotation
    modelTrans.setIdentity(); // reset
    modelTrans.postTranslate(xTrans, yTrans, zTrans);
    modelTrans.postRotate(totalDegrees, 0, 1, 0); // around y-axis
    } // end of updateModelTrans()
    // -----------------key operation methods ---------------------
    public void keyRepeated(int keyCode)
    int gameAction = getGameAction(keyCode);
    if (hasRepeatEvents())
    performAction( gameAction );
    protected void keyPressed(int keyCode)
    int gameAction = getGameAction(keyCode);
    // System.out.println("Can repeat: " + hasRepeatEvents());
    // if this MIDP doesn't support repeated keys
    // then initialise our key repeater
    if (!hasRepeatEvents())
    keyRepeater.startRepeat( gameAction );
    } // end of keyPressed()
    protected void keyReleased(int keyCode)
    int gameAction = getGameAction(keyCode);
    // if this MIDP doesn't support repeated keys
    // then stop our key repeater
    if (!hasRepeatEvents())
    keyRepeater.stopRepeat( gameAction );
    public void performAction(int gameAction)
    // called by KeyRepeat object or the keyRepeated() method
    if (gameAction == UP) {
    moveModel(0,MODEL_MOVE,0); // y up
    else if (gameAction == DOWN) {
    moveModel(0,-MODEL_MOVE,0); // y down
    else if (gameAction == LEFT) {
    moveModel(-MODEL_MOVE,0,0); // x left
    else if (gameAction == RIGHT) {
    moveModel(MODEL_MOVE,0,0); // x right
    else if (gameAction == GAME_A) {
    // System.out.println("fwd");
    moveModel(0,0,MODEL_MOVE); // z fwd
    else if (gameAction == GAME_B) {
    // System.out.println("back");
    moveModel(0,0,-MODEL_MOVE); // z back
    else if (gameAction == GAME_C) {
    // System.out.println("rot left");
    rotYModel(-MODEL_ROT); // rotate left
    else if (gameAction == GAME_D) {
    // System.out.println("rot right");
    rotYModel(MODEL_ROT); // rotate right
    } // end of keyPressed()
    private void moveModel(float x, float y, float z)
    // update the model's translation values
    { xTrans += x; yTrans += y; zTrans += z;
    repaint();
    private void rotYModel(float degrees)
    // update the model's y-axis rotation value
    { totalDegrees += degrees;
    repaint();
    } // end of rotYModel()
    // ----------------- data-specific methods added here -------
    The following methods can be pasted in from the ObjView application
    output stored in examObj.txt:
    private short[] getVerts() {...}
    private byte[] getNormals() {...}
    private short[] getTexCoords() (...}
    private short[] getColourCoords() (...}
    private int[] getStripLengths() {...}
    private Material setMatColours() {...}
    // Methods for model in hand.obj
    private short[] getVerts()
    // return an array holding Verts [2205 values / 3 = 735 points]
    short[] vals = {
    42,114,-5, 47,101,4, 52,114,-2, 47,101,4,
    61,111,-1, 47,101,4, 57,99,4, 50,83,9,
    57,99,4, 62,96,-2, 61,111,-1, 89,69,25,
    87,72,30, 97,68,28, 96,71,35, 101,62,33,
    83,69,38, 90,67,42, 87,72,30, 90,67,42,
    96,71,35, 95,63,46, 96,71,35, 100,66,39,
    101,62,33, 100,66,39, 101,56,38, 100,66,39,
    100,58,43, 95,63,46, 100,58,43, 97,59,47,
    92,51,49, 97,59,47, 87,55,49, 95,63,46,
    87,55,49, 90,67,42, 82,58,46, 83,69,38,
    77,61,42, 83,69,38, 77,69,34, 87,72,30,
    79,70,28, 87,72,30, 82,69,24, 89,69,25,
    82,69,24, 85,62,26, 82,69,24, 78,63,26,
    79,70,28, 74,64,30, 77,69,34, 73,64,36,
    77,61,42, 69,56,37, 77,61,42, 70,52,42,
    82,58,46, 70,52,42, 74,48,46, 70,52,42,
    64,43,40, 70,52,42, 64,46,35, 69,56,37,
    70,57,32, 73,64,36, 70,57,32, 74,64,30,
    70,57,32, 78,63,26, 74,55,28, 85,62,26,
    79,51,27, 85,62,26, 91,58,29, 89,69,25,
    91,58,29, 97,68,28, 91,58,29, 101,62,33,
    95,53,34, 101,56,38, 95,49,40, 100,58,43,
    94,49,45, 92,51,49, 87,40,46, 92,51,49,
    84,42,49, 87,55,49, 79,45,49, 82,58,46,
    79,45,49, 74,48,46, 71,37,46, 74,48,46,
    67,40,43, 64,43,40, 67,40,43, 59,36,38,
    67,40,43, 61,33,42, 67,40,43, 65,31,44,
    71,37,46, 69,29,44, 71,37,46, 76,35,46,
    79,45,49, 76,35,46, 84,42,49, 79,33,43,
    87,40,46, 88,40,41, 94,49,45, 88,40,41,
    95,49,40, 87,42,35, 95,53,34, 84,46,30,
    91,58,29, 84,46,30, 79,51,27, 75,41,26,
    79,51,27, 70,45,26, 74,55,28, 70,45,26,
    70,57,32, 66,47,30, 64,46,35, 59,38,33,
    64,43,40, 59,38,33, 59,36,38, 53,31,34,
    59,36,38, 53,29,39, 61,33,42, 55,27,43,
    65,31,44, 59,24,46, 65,31,44, 64,22,45,
    69,29,44, 69,20,42, 69,29,44, 74,27,40,
    76,35,46, 74,27,40, 79,33,43, 81,32,38,
    88,40,41, 81,34,33, 87,42,35, 78,37,29,
    84,46,30, 78,37,29, 75,41,26, 71,33,24,
    75,41,26, 66,36,23, 70,45,26, 66,36,23,
    66,47,30, 62,38,27, 59,38,33, 56,31,27,
    53,31,34, 51,31,26, 44,26,35, 41,39,27,
    30,29,29, 41,39,27, 31,51,20, 41,55,19,
    31,51,20, 35,68,14, 27,65,9, 32,83,4,
    27,65,9, 26,64,-1, 21,54,1, 26,64,-1,
    29,61,-8, 34,79,-12, 29,61,-8, 39,61,-8,
    36,45,-4, 45,51,2, 46,35,11, 47,41,19,
    51,31,26, 47,41,19, 41,39,27, 47,41,19,
    41,55,19, 47,41,19, 46,55,11, 45,51,2,
    49,67,6, 45,51,2, 47,64,-3, 39,61,-8,
    43,77,-12, 34,79,-12, 39,97,-16, 34,79,-12,
    30,81,-5, 26,64,-1, 30,81,-5, 32,83,4,
    37,102,-1, 32,83,4, 41,84,10, 35,68,14,
    44,69,14, 41,55,19, 44,69,14, 46,55,11,
    44,69,14, 49,67,6, 54,80,3, 49,67,6,
    52,78,-6, 47,64,-3, 52,78,-6, 43,77,-12,
    49,95,-16, 39,97,-16, 43,110,-17, 39,97,-16,
    34,100,-9, 30,81,-5, 34,100,-9, 37,102,-1,
    42,114,-5, 37,102,-1, 47,101,4, 41,84,10,
    50,83,9, 44,69,14, 50,83,9, 54,80,3,
    62,96,-2, 52,78,-6, 59,94,-10, 49,95,-16,
    59,94,-10, 63,107,-13, 62,96,-2, 64,111,-7,
    61,111,-1, 64,111,-7, 54,117,-11, 63,107,-13,
    54,110,-17, 49,95,-16, 54,110,-17, 43,110,-17,
    54,117,-11, 43,110,-17, 42,114,-12, 34,100,-9,
    42,114,-12, 42,114,-5, 54,117,-11, 52,114,-2,
    61,111,-1, 53,31,34, 44,26,35, 53,29,39,
    45,20,42, 55,27,43, 49,17,46, 59,24,46,
    53,14,48, 59,24,46, 58,12,48, 64,22,45,
    64,9,44, 69,20,42, 68,8,38, 69,20,42,
    73,19,36, 74,27,40, 77,26,35, 81,32,38,
    77,26,35, 81,34,33, 77,27,31, 81,34,33,
    75,29,27, 78,37,29, 75,29,27, 71,33,24,
    66,25,23, 66,36,23, 61,28,23, 62,38,27,
    61,28,23, 56,31,27, 52,23,19, 51,31,26,
    52,23,19, 46,35,11, 37,24,4, 36,45,-4,
    23,44,-6, 29,61,-8, 23,44,-6, 21,54,1,
    17,64,-11, 18,67,-3, 15,86,-17, 18,67,-3,
    18,89,-9, 14,91,-1, 14,112,-7, 3,111,-3,
    13,124,-11, 3,111,-3, 3,126,-10, -7,122,-10,
    3,126,-10, 3,127,-19, 13,124,-11, 15,125,-19,
    13,124,-11, 18,110,-15, 14,112,-7, 18,110,-15,
    18,89,-9, 15,107,-22, 15,86,-17, 15,107,-22,
    5,106,-24, 14,121,-24, 4,121,-25, 14,121,-24,
    3,127,-19, 14,121,-24, 15,125,-19, 14,121,-24,
    18,110,-15, 15,107,-22, -21,90,15, -27,101,22,
    -22,91,24, -29,90,31, -22,91,24, -17,76,25,
    -21,90,15, -16,75,16, -21,90,15, -26,88,11,
    -21,90,15, -28,101,16, -27,101,22, -38,102,22,
    -27,101,22, -34,101,28, -29,90,31, -34,101,28,
    -42,97,32, -38,102,22, -42,97,32, -46,97,28,
    -44,85,30, -46,97,28, -47,94,22, -38,102,22,
    -40,97,16, -28,101,16, -30,98,11, -26,88,11,
    -30,98,11, -36,85,14, -40,97,16, -36,85,14,
    -47,94,22, -44,84,22, -44,85,30, -37,70,29,
    -44,85,30, -38,87,34, -42,97,32, -38,87,34,
    -29,90,31, -38,87,34, -31,72,34, -37,70,29,
    -29,52,28, -37,70,29, -37,68,21, -44,84,22,
    -37,68,21, -36,85,14, -30,69,13, -26,88,11,
    -21,72,11, -16,75,16, -21,72,11, -10,59,14,
    -14,55,8, -5,51,10, -4,39,2, -5,51,10,
    -1,62,-7, -4,65,2, -7,86,-6, -4,89,2,
    -7,86,-6, -10,107,-12, -7,86,-6, -3,84,-15,
    -1,62,-7, 8,61,-12, -1,62,-7, 10,36,-6,
    -4,39,2, 10,36,-6, 12,5,1, 24,13,0,
    26,-12,7, 40,6,11, 45,-5,17, 58,14,22,
    63,10,26, 71,22,27, 63,10,26, 74,20,31,
    63,10,26, 68,8,31, 57,-10,30, 60,-8,37,
    52,-22,36, 60,-8,37, 47,-22,41, 56,-7,44,
    47,-22,41, 50,-4,48, 41,-20,46, 44,-2,49,
    35,-20,47, 44,-2,49, 31,-17,46, 40,0,47,
    31,-17,46, 35,2,43, 25,-18,43, 35,2,43,
    20,-11,39, 31,10,38, 20,-11,39, 19,17,29,
    10,12,31, 19,17,29, 8,43,21, 20,49,15,
    6,68,12, 15,69,7, 6,68,12, 5,91,4,
    -4,89,2, -7,109,-5, -10,107,-12, -7,109,-5,
    -7,122,-10, -7,109,-5, 3,111,-3, 5,91,4,
    14,91,-1, 15,69,7, 18,67,-3, 15,69,7,
    21,54,1, 20,49,15, 27,65,9, 20,49,15,
    31,51,20, 20,49,15, 30,29,29, 19,17,29,
    30,29,29, 31,10,38, 44,26,35, 31,10,38,
    45,20,42, 35,2,43, 49,17,46, 40,0,47,
    53,14,48, 44,-2,49, 53,14,48, 50,-4,48,
    58,12,48, 56,-7,44, 64,9,44, 56,-7,44,
    68,8,38, 60,-8,37, 68,8,38, 68,8,31,
    73,19,36, 74,20,31, 77,26,35, 74,20,31,
    77,27,31, 71,22,27, 75,29,27, 71,22,27,
    66,25,23, 58,14,22, 61,28,23, 58,14,22,
    52,23,19, 40,6,11, 37,24,4, 24,13,0,
    23,44,-6, 10,36,-6, 23,44,-6, 8,61,-12,
    17,64,-11, 8,61,-12, 6,84,-19, -3,84,-15,
    -6,105,-20, -10,107,-12, -6,119,-23, -10,107,-12,
    -8,122,-17, -7,122,-10, -8,122,-17, 3,127,-19,
    -6,119,-23, 4,121,-25, -6,119,-23, 5,106,-24,
    -6,105,-20, 5,106,-24, 6,84,-19, 15,86,-17,
    17,64,-11, 12,-123,45, 12,-47,17, 14,-127,44,
    16,-49,17, 17,-128,43, 20,-49,19, 20,-128,44,
    20,-49,22, 21,-127,47, 20,-49,22, 20,-125,49,
    18,-46,26, 17,-121,49, 15,-43,27, 17,-121,49,
    12,-44,27, 15,-122,49, 10,-47,26, 12,-123,45,
    10,-46,20, 12,-47,17, 5,-31,14, 12,-47,17,
    19,-38,13, 16,-49,17, 19,-38,13, 20,-49,19,
    33,-35,20, 20,-49,22, 30,-40,30, 18,-46,26,
    24,-35,40, 15,-43,27, 15,-31,40, 12,-44,27,
    6,-22,39, 12,-44,27, 0,-32,37, 10,-47,26,
    -2,-35,33, 10,-47,26, -1,-38,24, 10,-46,20,
    -1,-38,24, 5,-31,14, -1,-38,24, -8,-27,28,
    -2,-35,33, -5,-25,37, 0,-32,37, -3,-17,40,
    6,-22,39, 2,11,33, 6,-22,39, 13,-18,39,
    15,-31,40, 20,-26,42, 24,-35,40, 27,-27,44,
    24,-35,40, 32,-29,44, 24,-35,40, 38,-32,36,
    30,-40,30, 46,-27,29, 33,-35,20, 50,-10,22,
    33,-35,20, 27,-27,12, 19,-38,13, 17,-24,8,
    5,-31,14, 0,2,6, 5,-31,14, -8,-20,19,
    -8,-27,28, -14,-13,24, -8,-27,28, -13,-14,32,
    -5,-25,37, -9,-13,39, -3,-17,40, -6,11,37,
    2,11,33, -10,38,32, -3,45,23, -17,58,32,
    -11,60,24, -17,58,32, -23,75,32, -17,58,32,
    -24,55,33, -10,38,32, -17,35,33, -6,11,37,
    -13,10,37, -9,-13,39, -18,8,31, -13,-14,32,
    -18,8,31, -14,-13,24, -18,5,22, -14,-13,24,
    -11,3,14, -8,-20,19, -11,3,14, 0,2,6,
    -11,3,14, -16,31,11, -18,5,22, -23,30,20,
    -18,8,31, -23,32,29, -13,10,37, -23,32,29,
    -17,35,33, -23,32,29, -24,55,33, -29,52,28,
    -24,55,33, -31,72,34, -23,75,32, -29,90,31,
    -23,75,32, -17,76,25, -11,60,24, -16,75,16,
    -11,60,24, -10,59,14, -3,45,23, -5,51,10,
    -2,67,11, -4,65,2, -2,67,11, -4,89,2,
    -2,67,11, 6,68,12, -3,45,23, 8,43,21,
    2,11,33, 10,12,31, 13,-18,39, 20,-11,39,
    20,-26,42, 25,-18,43, 27,-27,44, 31,-17,46,
    27,-27,44, 35,-20,47, 32,-29,44, 41,-20,46,
    38,-32,36, 47,-22,41, 46,-27,29, 52,-22,36,
    46,-27,29, 57,-10,30, 50,-10,22, 63,10,26,
    50,-10,22, 45,-5,17, 27,-27,12, 26,-12,7,
    17,-24,8, 12,5,1, 0,2,6, -4,39,2,
    -16,31,11, -23,52,12, -16,31,11, -29,51,20,
    -23,30,20, -29,51,20, -23,32,29, -29,51,20,
    -29,52,28, -29,51,20, -37,68,21, -23,52,12,
    -30,69,13, -23,52,12, -21,72,11, -23,52,12,
    -14,55,8, -23,52,12, -4,39,2 };
    return vals;
    } // end of getVerts()
    private byte[] getNormals()
    // return an array holding Normals [2205 values / 3 = 735 points]
    byte[] vals = {
    -69,95,51, -17,51,116, -4,100,79, -17,51,116,
    66,68,87, -17,51,116, 62,17,111, 61,8,112,
    62,17,111, 122,-29,28, 66,68,87, 33,41,-117,
    -3,127,-8, 79,58,-82, 64,109,19, 114,-3,-59,
    -33,101,72, -10,95,85, -3,127,-8, -10,95,85,
    64,109,19, 47,73,94, 64,109,19, 114,48,34,
    114,-3,-59, 114,48,34, 120,-43,-14, 114,48,34,
    112,-16,59, 47,73,94, 112,-16,59, 64,23,109,
    62,-31,108, 64,23,109, -9,33,123, 47,73,94,
    -9,33,123, -10,95,85, -43,53,109, -33,101,72,
    -65,70,85, -33,101,72, -68,105,29, -3,127,-8,
    -74,94,-46, -3,127,-8, -34,61,-107, 33,41,-117,
    -34,61,-107, 8,-25,-125, -34,61,-107, -69,18,-106,
    -74,94,-46, -102,63,-45, -68,105,29, -103,73,25,
    -65,70,85, -107,60,37, -65,70,85, -84,46,85,
    -43,53,109, -84,46,85, -62,27,108, -84,46,85,
    -95,49,71, -84,46,85, -113,60,10, -107,60,37,
    -101,50,-61, -103,73,25, -101,50,-61, -102,63,-45,
    -101,50,-61, -69,18,-106, -39,11,-122, 8,-25,-125,
    24,-13,-125, 8,-25,-125, 51,-42,-110, 33,41,-117,
    51,-42,-110, 79,58,-82, 51,-42,-110, 114,-3,-59,
    78,-64,-80, 120,-43,-14, 101,-78,-15, 112,-16,59,
    97,-67,50, 62,-31,108, 77,-79,66, 62,-31,108,
    22,-44,118, -9,33,123, -32,5,124, -43,53,109,
    -32,5,124, -62,27,108, -37,-5,123, -62,27,108,
    -69,32,103, -95,49,71, -69,32,103, -87,71,62,
    -69,32,103, -60,57,98, -69,32,103, -25,25,123,
    -37,-5,123, 28,-29,121, -37,-5,123, 12,-56,115,
    -32,5,124, 12,-56,115, 22,-44,118, 67,-87,65,
    77,-79,66, 98,-83,-2, 97,-67,50, 98,-83,-2,
    101,-78,-15, 89,-60,-70, 78,-64,-80, 64,-38,-104,
    51,-42,-110, 64,-38,-104, 24,-13,-125, 46,4,-120,
    24,-13,-125, -28,36,-120, -39,11,-122, -28,36,-120,
    -101,50,-61, -85,60,-75, -113,60,10, -103,75,-15,
    -95,49,71, -103,75,-15, -87,71,62, -72,106,9,
    -87,71,62, -68,83,70, -60,57,98, -49,63,100,
    -25,25,123, -11,39,122, -25,25,123, 42,3,121,
    28,-29,121, 83,-29,93, 28,-29,121, 75,-65,81,
    12,-56,115, 75,-65,81, 67,-87,65, 97,-82,19,
    98,-83,-2, 106,-51,-51, 89,-60,-70, 83,-22,-95,
    64,-38,-104, 83,-22,-95, 46,4,-120, 51,-3,-118,
    46,4,-120, -17,32,-123, -28,36,-120, -17,32,-123,
    -85,60,-75, -76,61,-84, -103,75,-15, -50,94,-71,
    -72,106,9, 64,111,5, -42,88,83, 30,64,107,
    -39,51,111, 30,64,107, -35,52,111, 54,43,108,
    -35,52,111, -36,47,114, -100,55,57, -103,44,62,
    -100,55,57, -120,33,-29, 17,119,-45, -120,33,-29,
    -58,0,-114, -63,-8,-111, -58,0,-114, 43,-38,-115,
    56,-35,-110, 116,-26,-48, 115,0,-57, 119,35,32,
    64,111,5, 119,35,32, 30,64,107, 119,35,32,
    54,43,108, 119,35,32, 122,5,39, 116,-26,-48,
    123,-31,16, 116,-26,-48, 101,-46,-65, 43,-38,-115,
    34,-38,-117, -63,-8,-111, -60,-4,-113, -63,-8,-111,
    -123,24,-26, -120,33,-29, -123,24,-26, -103,44,62,
    -96,50,69, -103,44,62, -30,43,117, -36,47,114,
    71,12,106, 54,43,108, 71,12,106, 122,5,39,
    71,12,106, 123,-31,16, 115,-38,41, 123,-31,16,
    101,-55,-56, 101,-46,-65, 101,-55,-56, 34,-38,-117,
    32,-30,-120, -60,-4,-113, -40,46,-113, -60,-4,-113,
    -117,41,-30, -123,24,-26, -117,41,-30, -96,50,69,
    -69,95,51, -96,50,69, -17,51,116, -30,43,117,
    61,8,112, 71,12,106, 61,8,112, 115,-38,41,
    122,-29,28, 101,-55,-56, 94,-49,-72, 32,-30,-120,
    94,-49,-72, 96,8,-84, 122,-29,28, 116,54,1,
    66,68,87, 116,54,1, 26,121,-33, 96,8,-84,
    31,37,-119, 32,-30,-120, 31,37,-119, -40,46,-113,
    26,121,-33, -40,46,-113, -74,96,-40, -117,41,-30,
    -74,96,-40, -69,95,51, 26,121,-33, -4,100,79,
    66,68,87, -72,106,9, -42,88,83, -68,83,70,
    -66,63,90, -49,63,100, -52,49,106, -11,39,122,
    -17,23,125, -11,39,122, 39,-4,122, 42,3,121,
    80,-26,97, 83,-29,93, 109,-49,46, 83,-29,93,
    112,-52,35, 75,-65,81, 111,-63,14, 97,-82,19,
    111,-63,14, 106,-51,-51, 105,-50,-53, 106,-51,-51,
    82,-28,-94, 83,-22,-95, 82,-28,-94, 51,-3,-118,
    37,-15,-122, -17,32,-123, -12,37,-122, -76,61,-84,
    -12,37,-122, -50,94,-71, 68,33,-103, 64,111,5,
    68,33,-103, 115,0,-57, 69,-28,-104, 56,-35,-110,
    25,-15,-125, -58,0,-114, 25,-15,-125, 17,119,-45,
    91,-7,-90, 127,14,4, 88,-20,-91, 127,14,4,
    127,2,5, 90,29,86, 92,30,84, 12,47,119,
    68,82,71, 12,47,119, -4,99,82, -78,76,68,
    -4,99,82, -14,122,-35, 68,82,71, 94,85,-19,
    68,82,71, 127,16,1, 92,30,84, 127,16,1,
    127,2,5, 93,-15,-87, 88,-20,-91, 93,-15,-87,
    -1,-22,-126, 66,39,-103, -12,42,-121, 66,39,-103,
    -14,122,-35, 66,39,-103, 94,85,-19, 66,39,-103,
    127,16,1, 93,-15,-87, 113,50,-34, 77,95,38,
    107,48,51, 56,40,108, 107,48,51, 111,40,50,
    113,50,-34, 112,41,-46, 113,50,-34, 36,19,-121,
    113,50,-34, 44,100,-67, 77,95,38, -39,122,-10,
    77,95,38, 23,100,77, 56,40,108, 23,100,77,
    -35,64,105, -39,122,-10, -35,64,105, -106,59,41,
    -107,-27,65, -106,59,41, -117,18,-50, -39,122,-10,
    -62,64,-92, 44,100,-67, -13,48,-118, 36,19,-121,
    -13,48,-118, -69,-17,-107, -62,64,-92, -69,-17,-107,
    -117,18,-50, -114,-46,-35, -107,-27,65, -101,-49,62,
    -107,-27,65, -32,-4,124, -35,64,105, -32,-4,124,
    56,40,108, -32,-4,124, -23,-12,125, -101,-49,62,
    -104,-44,61, -101,-49,62, -109,-46,-49, -114,-46,-35,
    -109,-46,-49, -69,-17,-107, -60,-19,-112, 36,19,-121,
    28,19,-124, 112,41,-46, 28,19,-124, 103,63,-42,
    21,48,-117, -88,78,-51, -63,-5,-111, -88,78,-51,
    -104,-27,-70, -128,-4,9, -127,-18,-7, -92,20,86,
    -127,-18,-7, -128,-4,-5, -127,-18,-7, -91,-35,-84,
    -104,-27,-70, -18,-35,-122, -104,-27,-70, -28,-32,-121,
    -63,-5,-111, -28,-32,-121, -21,-29,-123, 34,-28,-120,
    44,-31,-116, 70,-21,-105, 70,-28,-103, 58,-15,-113,
    80,-38,-92, 75,-41,-96, 80,-38,-92, 105,-56,-46,
    80,-38,-92, 108,-55,-40, 99,-56,-60, 109,-63,24,
    97,-84,10, 109,-63,24, 71,-77,74, 78,-46,90,
    71,-77,74, 35,-26,121, 34,-55,111, -17,2,127,
    -11,-25,125, -17,2,127, -50,12,117, -53,29,113,
    -50,12,117, -62,37,106, -54,16,115, -62,37,106,
    -41,31,117, -56,49,104, -41,31,117, -19,46,118,
    6,37,122, -19,46,118, 25,44,118, -4,66,110,
    15,50,117, 94,42,76, 15,50,117, 14,41,120,
    -92,20,86, -73,31,101, -128,-4,-5, -73,31,101,
    -78,76,68, -73,31,101, 12,47,119, 14,41,120,
    90,29,86, 94,42,76, 127,14,4, 94,42,76,
    17,119,-45, -4,66,110, -100,55,57, -4,66,110,
    -35,52,111, -4,66,110, -39,51,111, -19,46,118,
    -39,51,111, -56,49,104, -42,88,83, -56,49,104,
    -66,63,90, -62,37,106, -52,49,106, -53,29,113,
    -17,23,125, -17,2,127, -17,23,125, 35,-26,121,
    39,-4,122, 78,-46,90, 80,-26,97, 78,-46,90,
    109,-49,46, 109,-63,24, 109,-49,46, 108,-55,-40,
    112,-52,35, 105,-56,-46, 111,-63,14, 105,-56,-46,
    105,-50,-53, 75,-41,-96, 82,-28,-94, 75,-41,-96,
    37,-15,-122, 58,-15,-113, -12,37,-122, 58,-15,-113,
    68,33,-103, 70,-21,-105, 69,-28,-104, 34,-28,-120,
    25,-15,-125, -28,-32,-121, 25,-15,-125, -18,-35,-122,
    91,-7,-90, -18,-35,-122, -8,-34,-123, -91,-35,-84,
    -77,-29,-98, -128,-4,-5, -78,25,-98, -128,-4,-5,
    -106,67,-25, -78,76,68, -106,67,-25, -14,122,-35,
    -78,25,-98, -12,42,-121, -78,25,-98, -1,-22,-126,
    -77,-29,-98, -1,-22,-126, -8,-34,-123, 88,-20,-91,
    91,-7,-90, -127,-9,-11, -74,-38,-98, -64,-36,-105,
    2,-41,-121, 22,-39,-120, 81,-49,-87, 111,-19,-61,
    119,-43,18, 127,5,11, 119,-43,18, 98,25,78,
    49,-43,110, 14,35,122, 3,-48,119, 14,35,122,
    -24,-34,121, -88,21,90, -92,-59,67, -127,-9,-11,
    -108,-53,-43, -74,-38,-98, -70,-49,-96, -74,-38,-98,
    17,-46,-119, 2,-41,-121, 17,-46,-119, 81,-49,-87,
    83,-72,-66, 119,-43,18, 64,-105,36, 49,-43,110,
    -3,-81,99, 3,-48,119, -24,-50,115, -24,-34,121,
    -5,-15,127, -24,-34,121, -15,-59,113, -92,-59,67,
    -86,-80,51, -92,-59,67, -97,-78,-29, -108,-53,-43,
    -97,-78,-29, -70,-49,-96, -97,-78,-29, -112,-62,-12,
    -86,-80,51, -84,-50,83, -15,-59,113, -1,-5,127,
    -5,-15,127, 34,31,119, -5,-15,127, -15,19,126,
    -24,-50,115, -36,-5,123, -3,-81,99, -33,-27,121,
    -3,-81,99, 21,-72,104, -3,-81,99, 60,-95,61,
    64,-105,36, 89,-90,-22, 83,-72,-66, 80,-43,-90,
    83,-72,-66, 56,-41,-108, 17,-46,-119, -6,-38,-122,
    -70,-49,-96, -58,-29,-111, -70,-49,-96, -88,-50,-79,
    -112,-62,-12, -118,-40,-30, -112,-62,-12, -116,-41,36,
    -84,-50,83, -69,-14,107, -1,-5,127, 15,19,126,
    34,31,119, 45,24,117, 56,61,98, 65,24,107,
    110,45,47, 65,24,107, 61,23,110, 65,24,107,
    -20,-9,126, 45,24,117, -29,5,125, 15,19,126,
    -63,2,112, -69,-14,107, -120,-21,39, -116,-41,36,
    -120,-21,39, -118,-40,-30, -117,-27,-45, -118,-40,-30,
    -88,-29,-89, -88,-50,-79, -88,-29,-89, -58,-29,-111,
    -88,-29,-89, -86,-24,-92, -117,-27,-45, -121,-31,-27,
    -120,-21,39, -109,-25,63, -63,2,112, -109,-25,63,
    -29,5,125, -109,-25,63, -20,-9,126, -104,-44,61,
    -20,-9,126, -23,-12,125, 61,23,110, 56,40,108,
    61,23,110, 111,40,50, 110,45,47, 112,41,-46,
    110,45,47, 103,63,-42, 56,61,98, -88,78,-51,
    -97,36,76, -128,-4,9, -97,36,76, -92,20,86,
    -97,36,76, 15,50,117, 56,61,98, 25,44,118,
    34,31,119, 6,37,122, -15,19,126, -41,31,117,
    -36,-5,123, -54,16,115, -33,-27,121, -50,12,117,
    -33,-27,121, -11,-25,125, 21,-72,104, 34,-55,111,
    60,-95,61, 71,-77,74, 89,-90,-22, 97,-84,10,
    89,-90,-22, 99,-56,-60, 80,-43,-90, 80,-38,-92,
    80,-43,-90, 70,-28,-103, 56,-41,-108, 44,-31,-116,
    -6,-38,-122, -21,-29,-123, -58,-29,-111, -63,-5,-111,
    -86,-24,-92, -72,-16,-105, -86,-24,-92, -116,-40,-37,
    -121,-31,-27, -116,-40,-37, -109,-25,63, -116,-40,-37,
    -104,-44,61, -116,-40,-37, -109,-46,-49, -72,-16,-105,
    -60,-19,-112, -72,-16,-105, 28,19,-124, -72,-16,-105,
    21,48,-117, -72,-16,-105, -63,-5,-111 };
    return vals;
    } // end of getNormals()
    private int[] getStripLengths()
    // return an array holding the lengths of each triangle strip
    int[] lens = {
    11, 5, 257, 77, 199, 186
    return lens;
    } // end of getStripLengths()
    private Material setMatColours()
    // set the material's colour and shininess values
    Material mat = new Material();
    mat.setColor(Material.AMBIENT, 0x00765D4D);
    mat.setColor(Material.EMISSIVE, 0x00000000);
    mat.setColor(Material.DIFFUSE, 0xFF876A56);
    mat.setColor(Material.SPECULAR, 0x004D4D4D);
    mat.setShininess(60.0f);
    return mat;
    } // end of setMatColours()
    } // end of HandCanvas class
    -- class 3 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    // KeyRepeat.java
    // Andrew Davison, [email protected], July 2004
    /* Repeat key presses. The repetition speed is slow at first
    then speeds up after a certain amount of time.
    Based on ideas from the article:
    "Using the Low-level GUI - Repeating Keys"
    Roman Bialach, microdevnet, August 2001
    http://www.microjava.com/articles/techtalk/repeating
    import javax.microedition.lcdui.*;
    public class KeyRepeat extends Thread
    p

    Hi,
    I hope your problem is solved within the thread at http://forum.java.sun.com/thread.jspa?threadID=577857. Anyway, there are Java 3D examples bundled with latest netBeans Mobility Pack (see http://www.netbeans.info/downloads/download.php?type=rc2&p=1 for both netBeans 4.0 RC2 and said Mobility Pack). These will give you overview of what can and can't be done using Java 3D.
    Peter

  • HttpConnection hangs in my T630. Please Help !

    Hi all,
    I`ve noticed this problem in a few threads on this forum, but none of them seem to have a definitive answer. Maybe we can answer it once and for all here :-) Any help would be greatly appreciated.
    I`m trying to load a web page from a midlet in my T630. As I don`t really want to pay for call charges during development, I`m using the "Device Explorer" and the "Connection proxy" to try and connect to the internet using my broadband connection. I'm using the SonyEricsson developer kit (version 1) and I'm using a bluetooth serial connection on COM5 for the connection proxy.
    I've based my code on some sample code from Sun to load some info from a web page. This code was even published to get around the IO blocking problem that I seem to be getting still !
    The problem is when I try and use the HttpConnection.getResponseCode() method. Using the advice of other internet resources, I`ve put this code in its own thread. When I call HttpConnection.getResponseCode(), my T630 then pops ups with a menu, offering me these 3 options:
    Allow Web access
    Ask per access
    Deny Web access
    When this happens, it`s as if the thread running the getResponseCode() method blocks, and the T630 OS takes over. When I select an item from that menu, control does not pass back to the thread running getResponseCode(), but goes to the main midlet thread. Once I`m back in the main midlet thread, I don't know how to wake up the url loading thread. Does anyone have any ideas.
    My debugging statements produce the following before the app hangs:
    url=http://java.sun.com
    conn=com.sun.midp.io.j2me.http.Protocol@e4857a1d
    here
    Connecting to http://java.sun.comHere is the source code:
    package com.pg.midp.http;
    import java.io.IOException;
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.lcdui.Alert;
    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.TextBox;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    // Simple class that connects to a given URL and
    // prints out the response code and any headers
    // that are sent back. Shows how to use background
    // threads to make HTTP connections while keeping the
    // user interface alive.
    public class HttpLogger extends MIDlet
         private Display display;
         private Command exitCommand = new Command([quot][/quot]Exit[quot][/quot], Command.EXIT, 1);
         private Command okCommand = new Command([quot][/quot]OK[quot][/quot], Command.OK, 1);
         private Command cancelCommand = new Command([quot][/quot]Cancel[quot][/quot], Command.CANCEL, 1);
         private URLEntry mainForm;
         // Standard MIDlet stuff....
         public HttpLogger()
         protected void debug(String s)
              System.out.println(s);
         protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
              exitMIDlet();
         protected void pauseApp()
         protected void startApp() throws MIDletStateChangeException
              if (display == null)
                   initMIDlet();
         private void initMIDlet()
              display = Display.getDisplay(this);
              mainForm = new URLEntry();
              display.setCurrent(mainForm);
         public void exitMIDlet()
              notifyDestroyed();
         // Utility routine to display exceptions.
         void displayError(Throwable e, Displayable next)
              Alert a = new Alert([quot][/quot]Exception[quot][/quot]);
              a.setString(e.toString());
              a.setTimeout(Alert.FOREVER);
              display.setCurrent(a, next);
         // Simple entry form for entering the URL to
         // connect to.
         class URLEntry extends TextBox implements CommandListener
              URLEntry()
                   super([quot][/quot]Enter URL:[quot][/quot], [quot][/quot]java.sun.com[quot][/quot], 100, 0);
                   addCommand(exitCommand);
                   addCommand(okCommand);
                   setCommandListener(this);
              public void commandAction(Command c, Displayable d)
                   if (c == exitCommand)
                        exitMIDlet();
                   else if (c == okCommand)
                        try
                             String url = [quot][/quot]http://[quot][/quot] + getString();
                             debug([quot][/quot]url=[quot][/quot] + url);
                             HttpConnection conn = (HttpConnection) Connector.open(url);
                             debug([quot][/quot]conn=[quot][/quot] + conn);
                             Logger logger = new Logger(this, conn);
                             debug([quot][/quot]here[quot][/quot]);
                             display.setCurrent(logger);
                        catch (IOException e)
                             displayError(e, this);
         //      Simple form that contains a single string item.
         //      The string item is updated with status messages.
         //      When constructed, it starts a background thread
         //      that makes the actual HTTP connection. Displays
         //      a Cancel command to abort the current connection.
         class Logger extends Form implements Runnable, CommandListener
              private Displayable next;
              private HttpConnection conn;
              private StringItem text = new StringItem(null, [quot][/quot][quot][/quot]);
              boolean done = false;
              Thread t;
              Logger(Displayable next, HttpConnection conn)
                   super([quot][/quot]HTTP Log[quot][/quot]);
                   this.next = next;
                   this.conn = conn;
                   addCommand(cancelCommand);
                   setCommandListener(this);
                   append(text);
                   t = new Thread(this);
                   t.start();
              // Handle the commands. First thing to do
              // is switch the display, in case closing/
              // the connection takes a while...
              public void commandAction(Command c, Displayable d)
                   display.setCurrent(next);
                   try
                        conn.close();
                   catch (IOException e)
                        displayError(e, next);
              // Do the connection and processing on
              // a separate thread...
              public void run()
                   try
                        update([quot][/quot]Connecting to [quot][/quot] + conn.getURL());
                        try
                             int rc = conn.getResponseCode();
                             update([quot][/quot]Response code: [quot][/quot] + rc);
                             update([quot][/quot]Response message: [quot][/quot] + conn.getResponseMessage());
                             String key;
                             for (int i = 0; (key = conn.getHeaderFieldKey(i)) != null; ++i)
                                  update(key + [quot][/quot]: [quot][/quot] + conn.getHeaderField(i));
                        catch (IOException e)
                             update([quot][/quot]Caught exception: [quot][/quot] + e.toString());
                   catch (Exception e)
                        debug(e.getMessage());
                        e.printStackTrace();
                   finally
                   done = true;
                   removeCommand(cancelCommand);
                   addCommand(okCommand);
              // Update the string item with new information.
              // Only do it if we're actually visible.
              void update(String line)
                   debug(line);
                   if (display.getCurrent() != this)
                        return;
                   String old = text.getText();
                   StringBuffer buf = new StringBuffer();
                   buf.append(old);
                   if (old.length() [gt][/gt] 0)
                        buf.append('\n');
                   buf.append(line);
                   text.setText(buf.toString());
    }Thanks,
    Paul.

    Hi, Paulgrime:
    These days I also have struggled with the problem.
    I just saw a java example from SUN site, which does not use getResponseCode(). It seems a good work around.
    I tried that way and works fine. Only thing is you have to figure out the response status by analysing the inputstream content, which is actually easy.
    So I go this way now.
    Huiyi

  • Help accessinf Form via HTTP

    Hi All,
    I am triying to fill an form, without luck.
    Some codes blocks my emulator.
    Now I have an code which I got problem when I try to pass parameters.
    If I use this code without passing paremters (teh variavels of filled in the form) its works ok.
    I got the message:
    "Uncaught exception java/lang/NullPointerException"
    Can somebody help me??
    Thanks in advance.
    Here�s the code:
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    Tento por um form neste treco
    public class HttpContacts extends MIDlet implements CommandListener {
    private Display mDisplay;
    private Form mMainForm;
    private StringItem mMessageItem;
    private Command mExitCommand, mConnectCommand;
    private TextField username, password;
    public HttpContacts() {
    mMainForm = new Form("Enter Username and Password");
    mExitCommand = new Command("Exit", Command.EXIT, 0);
    mConnectCommand = new Command("Connect",Command.SCREEN, 0);
    username = new TextField("Username:", null, 30, TextField.ANY);
    mMainForm.append(username);
    password = new TextField("Password", null, 30, TextField.PASSWORD);
    mMainForm.append(password);
    mMainForm.addCommand(mExitCommand);
    mMainForm.addCommand(mConnectCommand);
    mMainForm.setCommandListener(this);
    public void startApp() {
    mDisplay = Display.getDisplay(this);
    mDisplay.setCurrent(mMainForm);
    public void pauseApp() {}
    public void destroyApp(boolean unconditional) {}
    public void commandAction(Command c, Displayable s) {
    if (c == mExitCommand)
    notifyDestroyed();
    else if (c == mConnectCommand) {
    Form waitForm = new Form("Waiting...");
    mDisplay.setCurrent(waitForm);
    Thread t = new Thread() {
    public void run() {
         try {
              connect(username.getString(), password.getString());
    //connect();
         catch (IOException ioe) {
              mMessageItem.setText(ioe.toString());
    t.start();
    private void connect(String username, String password) throws IOException {
    HttpConnection hc = null;
    InputStream in = null;
    //String url = getAppProperty("HelloMIDlet.URL");
    String url = "http://localhost:8080/midp/hits?" + "user=" + username + "&" + "pass=" + password;
    try {
    hc = (HttpConnection)Connector.open(url);
    in = hc.openInputStream();
    int contentLength = (int)hc.getLength();
    byte[] raw = new byte[contentLength];
    int length = in.read(raw);
    in.close();
    hc.close();
    // Show the response to the user.
    String s = new String(raw, 0, length);
    mMessageItem.setText(s);
    catch (IOException ioe) {
    mMessageItem.setText(ioe.toString());
    mDisplay.setCurrent(mMainForm);

    Hi.I'd like to develop an application that interacts with a HTTP server. Can i develop and TEST the application in the UIQ emulator?or the testing part has to be done in the cell phone?Please help me.

  • Please help me with my code (has conversion from string to int)

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class Test3 extends MIDlet implements CommandListener
    {   Form mForm;
        Command mCommandQuit;
        Command mCommandItem;
        TextField input,prime1,prime2,prime3,output;
        Display mDisplay;
        int i,j=0,k1,k2,p,q,b;
        //int [] current=new int [1000];
        String mstring,a="";
        String [] temp=new String [1000];
        public void startApp()
        {System.out.println("startApp");
         mForm=new Form("RSA Encryption");
         mCommandQuit=new Command("QUIT",Command.EXIT,0);
         mCommandItem=new Command("ENCRYPT",Command.ITEM,0);
         mForm.append("Enter text:\n");
         input=new TextField(null,"",100, TextField.ANY);
         mForm.append(input);
         mForm.append("Enter first prime number(p):\n");
         prime1=new TextField(null,"",100, TextField.ANY);
         mForm.append(prime1);
         mForm.append("Enter second prime number(q):\n");
         prime2=new TextField(null,"",100, TextField.ANY);
         mForm.append(prime2);
         mForm.append("Enter d:\n");
         prime3=new TextField(null,"",100, TextField.ANY);
         mForm.append(prime3);
         mForm.addCommand(mCommandQuit);
         mForm.addCommand(mCommandItem);
         mDisplay=Display.getDisplay(this);
         mDisplay.setCurrent(mForm);
         mForm.setCommandListener(this);
        public void pauseApp()
        {System.out.println("pauseApp");
        public void destroyApp(boolean unconditional)
        {System.out.println("destroyApp");
        public void commandAction(Command c, Displayable d)
        {System.out.println("commandAction");
         if(c==mCommandQuit)
            notifyDestroyed();
         else if(c==mCommandItem)
         {p = Integer.parseInt(prime1.getString());
             q = Integer.parseInt(prime2.getString());
             b = Integer.parseInt(prime3.getString());
             //breaking up of big string into ints
             mstring=input.getString();
             temp[0]="";
             for(i=1;i<mstring.length();i++)
                {if (mstring.charAt(i) == ' ')
                    {j++;
                     temp[j]="";
                 else
                    {temp[j]=temp[j]+mstring.charAt(i);
             mForm.append("\n\nThe array is:\n");
             for(i=0;i<temp.length && temp!=null;i++)
    {k1=Integer.parseInt(temp[i]); ***********************
    k2=k1;
    for(j=1;j<b;j++)
    {k1=k1*k2;
    k1=k1 %(p*q);
    k2=k1 %(p*q);
    a=a+new Character((char)k2).toString();
    output=new TextField(null,a,100, TextField.ANY);
    mForm.append(output);
    }hi
    this code basically takes an input of string like " 179 84 48 48 155 " (with spaces)
    then it creates smaller strings in an array like "179","84","48","48","155" without the spaces
    then it creates int values 179,84,48,48,155 and finally after some math functions it prints the corresponding letters.
    the problem is that it is not printing the letter because of some exceptions-->java.lang.NumberFormatException .it comes in the line where i have put stars
    could anybody please help me print the letters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    thanks for all ur help guys, but me and my team member solved it on our own. here is the new code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class Test3 extends MIDlet implements CommandListener
    {   Form mForm;
        Command mCommandQuit;
        Command mCommandItem;
        TextField input,prime1,prime2,prime3,output;
        Display mDisplay;
        int i,j=0,l,k1,k2,p,q,n,b;
        String mstring,a = "";
        String [] temp=new String [1000];
        public void startApp()
        {System.out.println("startApp");
         mForm=new Form("RSA Encryption");
         mCommandQuit=new Command("QUIT",Command.EXIT,0);
         mCommandItem=new Command("DECRYPT",Command.ITEM,0);
         mForm.append("Enter text:\n");
         input=new TextField(null,"",100, TextField.ANY);
         mForm.append(input);
         mForm.append("Enter first prime number(p):\n");
         prime1=new TextField(null,"",100, TextField.NUMERIC);
         mForm.append(prime1);
         mForm.append("Enter second prime number(q):\n");
         prime2=new TextField(null,"",100, TextField.NUMERIC);
         mForm.append(prime2);
         mForm.append("Enter d:\n");
         prime3=new TextField(null,"",100, TextField.NUMERIC);
         mForm.append(prime3);
         mForm.addCommand(mCommandQuit);
         mForm.addCommand(mCommandItem);
         mDisplay=Display.getDisplay(this);
         mDisplay.setCurrent(mForm);
         mForm.setCommandListener(this);
        public void pauseApp()
        {System.out.println("pauseApp");
        public void destroyApp(boolean unconditional)
        {System.out.println("destroyApp");
        public void commandAction(Command c, Displayable d)
        {System.out.println("commandAction");
         if(c==mCommandQuit)
            notifyDestroyed();
         else if(c==mCommandItem)
         {p = Integer.parseInt(prime1.getString());
             q = Integer.parseInt(prime2.getString());
             b = Integer.parseInt(prime3.getString());
             n=p*q;
             //breaking up of big string into ints
             mstring=input.getString();
             temp[0]="";
             for(i=1;i<mstring.length();i++)
                {if (mstring.charAt(i) == ' ')
                    {j++;
                     temp[j]="";
                 else
                    {temp[j]=temp[j]+mstring.charAt(i);
             l=j;
             mForm.append("\n\nThe result is:\n");
             for(i=0;i<l;i++)
                {k1=Integer.valueOf(temp).intValue();
    k2=k1;
    for(j=1;j<b;j++)
    {k2=k2*k1;
    k2=k2 %n;
    k1=k2 %n;
    a=a+new Character((char)k1).toString();
    output=new TextField(null,a,100, TextField.ANY);
    mForm.append(output);

  • Please Mr. prabhu_cbe Help me!

    Dear Mr. prabhu_cbe.......it seems that you are the top jguru here and I was wondering if you could help me out!......I am having a problem that i cannot figure out!.....Below is the code.....the problem that I am having is that I have put a picture in the picture menu but the picture ends up in the capapcity menu.....also you notice that i have textbox with some writing but that does not show up!.....Any help would be great and thank you very much for your time in advance!
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class testMIDlet extends MIDlet implements CommandListener
    Display display = null;
    List menu;
    List Area;
    List Staff;
    List Players;
    TextBox input = null;
    private Form fmMain;
    private Command cmExit;
    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);
    String currentMenu = null;
    public testMIDlet() {
    public void startApp() throws MIDletStateChangeException {
    display = Display.getDisplay(this);
    menu = new List("Oulun K�rp�t", Choice.IMPLICIT);
    menu.append("Area", null);
    menu.append("Staff", null);
    menu.append("Players", null);
    menu.addCommand(exitCommand);
    menu.setCommandListener(this);
    mainMenu();
    public void pauseApp() {
    display = null;
    menu = null;
    input = null;
    public void destroyApp(boolean unconditional) {
    notifyDestroyed();
    void mainMenu() {
    display.setCurrent(menu);
    currentMenu = "main";
    public void AreaMenu() {
    Area = new List("Oulu J��halli", Choice.IMPLICIT);
    Area.append("Picture", null);
    Area.append("Capacity", null);
    Area.append("Location", null);
    Area.addCommand(backCommand);
    Area.setCommandListener(this);
    display.setCurrent(Area);
    currentMenu = "Area";
    public void testPicture()
              display = Display.getDisplay(this);
              cmExit = new Command("Back", Command.BACK, 1);
              fmMain = new Form("");
              fmMain.addCommand(cmExit);
              fmMain.setCommandListener(this);
    try
         // Read the appropriate image based on color support
         Image im = Image.createImage("/rinne_pekka.png");
         fmMain.append(new ImageItem(null, im, ImageItem.LAYOUT_CENTER, null));
         display.setCurrent(fmMain);
         catch (java.io.IOException e)
         System.err.println("Unable to locate or read .png file");
    currentMenu = "Picture";
    public void testCapacity()
         input = new TextBox("Oulu J��halli: ", "ruweruwyuery", 250, TextField.ANY);
              input.addCommand(backCommand);
              input.setCommandListener(this);
              input.setString("");
              display.setCurrent(input);
    currentMenu = "Capacity";
    public void testLocation()
              input = new TextBox("Oulu J��halli: ", "blah", 250, TextField.ANY);
                   input.addCommand(backCommand);
                   input.setCommandListener(this);
                   input.setString("");
                   display.setCurrent(input);
         currentMenu = "Location";
    public void StaffMenu()
    Staff = new List("Staff", Choice.IMPLICIT);
    Staff.append("Coach", null);
    Staff.append("Assistant Coach", null);
    Staff.append("Trainers", null);
    Staff.addCommand(backCommand);
    Staff.setCommandListener(this);
    display.setCurrent(Staff);
    currentMenu = "Staff";
    public void testCoach()
              input = new TextBox("Oulu K�rp�t Coach: ", "blah", 250, TextField.ANY);
                   input.addCommand(backCommand);
                   input.setCommandListener(this);
                   input.setString("");
                   display.setCurrent(input);
         currentMenu = "Coach";
         public void testAssistant_Coach()
              input = new TextBox("Oulu K�rp�t Assistant Coach: ", "blah", 250, TextField.ANY);
                   input.addCommand(backCommand);
                   input.setCommandListener(this);
                   input.setString("");
                   display.setCurrent(input);
         currentMenu = "Assistant Coach";
    public void testTrainers()
              input = new TextBox("Oulu K�rp�t Trainers: ", "blah", 250, TextField.ANY);
                   input.addCommand(backCommand);
                   input.setCommandListener(this);
                   input.setString("");
                   display.setCurrent(input);
         currentMenu = "Trainers";
    public void PlayersMenu() {
    Players = new List("Players", Choice.IMPLICIT);
    Players.append("Backstrom", null);
    Players.append("Rinne", null);
    Players.append("Korpikari", null);
    Players.append("Jaakola", null);
    Players.addCommand(backCommand);
    Players.setCommandListener(this);
    display.setCurrent(Players);
    currentMenu = "Players";
    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("Area") || currentMenu.equals("Picture") ||
    currentMenu.equals("Capacity") || currentMenu.equals("Location") ||
    currentMenu.equals("Staff") || currentMenu.equals("Coach")|| currentMenu.equals("Assistant Coach")
    || currentMenu.equals("Trainers") || currentMenu.equals("Players")) {
    // go back to menu
    mainMenu();
    } else {
    List down = (List)display.getCurrent();
    switch(down.getSelectedIndex()) {
    case 0: AreaMenu();break;
    case 1: testPicture();break;
    case 2: testCapacity();break;
    case 3: testLocation();break;
    case 4: StaffMenu();break;
    case 5: testCoach();break;
    case 6: testAssistant_Coach();break;
    case 7: testTrainers();break;
    case 8: PlayersMenu();break;

    Hi,
    Change commandAction like this.
    And i would suggest you to remove the code from MIDlet clas and use seperate class for List and Form.
    Please see the example apps that come with WTK.
    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("Area") || currentMenu.equals("Picture") ||
    currentMenu.equals("Capacity") || currentMenu.equals("Location") ||
    currentMenu.equals("Staff") || currentMenu.equals("Coach")|| currentMenu.equals("Assistant Coach")
    || currentMenu.equals("Trainers") || currentMenu.equals("Players")) {
    // go back to menu
    mainMenu();
    } else {
    List down = (List)display.getCurrent(); //this might throw exception coz sometimes commandAction may //be invoked from a Form.
    String label = down.getString(down.getSelectedIndex());
    if(label.equals("Picture")) {
         testPicture();
    } else if(label.equals("Location")) {
         testLocation();
    And change ur code withthe following strucuture
    class MyMIDlet extends MIDlet {
    public void startApp() {
    display.setCurrent(new MyForm());
    class MyForm extends Form {
    public void commandAction(Command c, Displayable d) {
    if(...) {
    display.setCurrent(new MyList());
    class MyList extends List {

  • Help in J2ME

    Hello Sir/Mam,
    Im Sanjeev Das from Bhilai(C.G.). Doing my B.E.(C.S.) and in final year from RCET, Bhilai.And has been selected by RISPL, Bhilai and Lambent, Nagpur mobiles companies.
    My J2ME training was completed from RISPL on June of calendar year. RISPL is the Bhilai`s only InfoTech company that works on J2ME and Brew Tech.
    Now with my hand I have three Game :-
    1. Chakravue....(The Maze).
    2. Tic-Tac-Toe.
    3. Brick Game.
    Now Im interested in application program that�s why my next project is �MobileBluetoothApplication� in which Im providing user to exchange data like image, text, sound�etc files through Bluetooth.
    But one problem is there. Im not able to send the text and sound files through the Bluetooth. Please help me so that my project can grow up and perform the best result.

    Hi !
    Place this code net benas file or any editor
    it will work on stand alone phone
    Premal
    * TicTacToe.java
    * Created on April 4, 2006, 10:14 PM
    * @author  premal lathiya
    * @version
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class TicTacToe extends MIDlet
        private Display display;
        private MyCanvas canvas;
        public TicTacToe ()
            display = Display.getDisplay(this);       
        protected void startApp()
            canvas = new MyCanvas (this);
            display.setCurrent( canvas );
        protected void pauseApp()
        protected void destroyApp( boolean unconditional )
        public void exitMIDlet()
            destroyApp(true);
            notifyDestroyed();
    class MyCanvas extends Canvas implements CommandListener
        private Command exit, restart;
        private TicTacToe ticTacToe;
        int[] gameArr= new int[10];
        int position[][]=new int[10][2];
        int startX=2;
        int startY=2;
        boolean b=true, gameOverFlag=false;
        Image img1,img2;
        public MyCanvas (TicTacToe ticTacToe)
            this.ticTacToe = ticTacToe;
            exit = new Command("Exit", Command.EXIT, 1);
            restart = new Command("Restart", Command.SCREEN, 1);
            addCommand(exit);
            setCommandListener(this);
            position[1][0]=startX;
            position[1][1]=startY;
            position[2][0]=(getWidth())/3;
            position[2][1]=startY;
            position[3][0]=2*((getWidth())/3);
            position[3][1]=startY;
            position[4][0]=startX;
            position[4][1]=(getHeight()-50)/3;
            position[5][0]=(getWidth())/3;
            position[5][1]=(getHeight()-50)/3;
            position[6][0]=2*((getWidth())/3);
            position[6][1]=(getHeight()-50)/3;
            position[7][0]=startX;
            position[7][1]=2*((getHeight()-50)/3);
            position[8][0]=(getWidth())/3;
            position[8][1]=2*((getHeight()-50)/3);
            position[9][0]=2*((getWidth())/3);
            position[9][1]=2*((getHeight()-50)/3);
            for(int i=0;i<10;i++)
            {   gameArr[i] =0;
        protected void paint(Graphics graphics)
            int width=getWidth();
            int height=getHeight();
            boolean flag=false;
            graphics.setColor(255,255,255);
            graphics.fillRect(0, 0, width, height);
            graphics.setColor(255,0,0);
            graphics.drawRect(startX, startY, width-10, height-50);
            graphics.drawLine(width/3,2,width/3,height-50+2);
            graphics.drawLine(2*(width/3),2,2*(width/3),height-50+2);
            graphics.drawLine(2,(height-50)/3,width-8,(height-50)/3);
            graphics.drawLine(2,2*(height-50)/3,width-8,2*(height-50)/3);
            for(int i=1;i<10;i++)
                if (gameArr[i] != 0)
                    if(gameArr==1)
    graphics.drawString("0", position[i][0]+5,position[i][1]+5,0); //zero
    else
    graphics.drawString("X", position[i][0]+5,position[i][1]+5,0); //zero
    if(gameArr[i] == 0)
         flag = true;
    if(flag == false)
         graphics.drawString("No Result", getWidth() / 3, getHeight() - 30, 0);
         addCommand(restart);
    else if(gameOverFlag && !b)
    graphics.drawString("Player-1 wins", getWidth() / 3, getHeight() - 30, 0);
    else if(gameOverFlag && b)
    graphics.drawString("Player-2 wins", getWidth() / 3, getHeight() - 30, 0);
    public void commandAction(Command command, Displayable displayable)
    if (command == exit)
    ticTacToe.exitMIDlet();
    else if(command == restart)
    ticTacToe.startApp();
    protected void keyPressed(int key)
    if(gameOverFlag)
    return;
    switch ( key )
    case KEY_NUM1:
    setValue(1);
    break;
    case KEY_NUM2:
    setValue(2);
    break;
    case KEY_NUM3:
    setValue(3);
    break;
    case KEY_NUM4:
    setValue(4);
    break;
    case KEY_NUM5:
    setValue(5);
    break;
    case KEY_NUM6:
    setValue(6);
    break;
    case KEY_NUM7:
    setValue(7);
    break;
    case KEY_NUM8:
    setValue(8);
    break;
    case KEY_NUM9:
    setValue(9);
    break;
    repaint();
    checkWin();
    public void setValue(int subScript){
    if(gameArr[subScript] == 0){
    if(b)
    gameArr[subScript] = 1; //zero
    else
    gameArr[subScript] = 2; //cross
    b=!b;
    public void checkWin()
    if((gameArr[1] == 1 && gameArr[2] == 1 && gameArr[3] == 1) ||
    (gameArr[4] == 1 && gameArr[5] == 1 && gameArr[6] == 1) ||
    (gameArr[7] == 1 && gameArr[8] == 1 && gameArr[9] == 1) ||
    (gameArr[1] == 1 && gameArr[4] == 1 && gameArr[7] == 1) ||
    (gameArr[2] == 1 && gameArr[5] == 1 && gameArr[8] == 1) ||
    (gameArr[3] == 1 && gameArr[6] == 1 && gameArr[9] == 1) ||
    (gameArr[1] == 1 && gameArr[5] == 1 && gameArr[9] == 1) ||
    (gameArr[3] == 1 && gameArr[5] == 1 && gameArr[7] == 1))
    gameOverFlag = true;
    addCommand(restart);
    if((gameArr[1] == 2 && gameArr[2] == 2 && gameArr[3] == 2) ||
    (gameArr[4] == 2 && gameArr[5] == 2 && gameArr[6] == 2) ||
    (gameArr[7] == 2 && gameArr[8] == 2 && gameArr[9] == 2) ||
    (gameArr[1] == 2 && gameArr[4] == 2 && gameArr[7] == 2) ||
    (gameArr[2] == 2 && gameArr[5] == 2 && gameArr[8] == 2) ||
    (gameArr[3] == 2 && gameArr[6] == 2 && gameArr[9] == 2) ||
    (gameArr[1] == 2 && gameArr[5] == 2 && gameArr[9] == 2) ||
    (gameArr[3] == 2 && gameArr[5] == 2 && gameArr[7] == 2))
    gameOverFlag = true;
    addCommand(restart);

  • WAD - adding menu entries with JavaScript - help please!

    Hiya,
    I am completely new to JavaScript and I need some help with adding menu entries into my WAD template. Can anyone please help?
    I want to add functionality into my WAD template to enable users adding results rows on a selected characteristic, at a single mouse click. Currently they need to go to the menu -> properties -> characteristic -> display results -> always -> ok. That's five clicks of a mouse (provided they know were to go).
    I want to add this option to the basic menu so that they can click once only.
    What I have managed to figure out so far using SAP help is the following. I have added a Script Item into my WAD Layout and added the following line of code in the Script Editing window:
    sapbi_addToMenu("Add totals", "alternate_context_menu", "X","CHARACTERISTIC", "", "bottom", "", "")
    It worked fine in that it added an extra item "Add totals" to my menu when I righclick on a characteristic. So far so good. However, I have no idea what function I should be using here, or how to code it. Surely WAD uses some function to perform this action, something that I could reuse? Is there a library somewhere of all the function used in WAD?
    Can anyone please help with the code?
    Many thanks,
    Agata

    Hiya again,
    I have managed to partially solve this problem by using the following code. However it requires me to define on which characteristic the function is performed. In this case I have managed to get it working on 0PROJECT, but I want it to be ANY characteristic which has been right clicked?
    Any ideas how I can pass the characteristic name as a VARIABLE, whose value would be read automatically when menu is triggered?
    /* Add Contextmenu entries */
    sapbi_addToMenu("Add totals", "JS_SET_RESULT_VISIBILITY_R", "X","CHARACTERISTIC", "", "bottom", "", "")
    * Javascript functions that are to be integrated into a web template and that
    * are to be used later in the web application ALWAYS have to have the same function
    * signature, i.e. the parameters that will be passed.
    * @param currentState - a list of parameters that describe the state the web item
    * @param defaultCommandSequence - the initially used sequence of commands that
    *       would have been used instead of the custom
    *       script.
    function JS_SET_RESULT_VISIBILITY_R( currentState, defaultCommandSequence ){
    //Note: information can be extracted using the parameter 'currentState'
    // and 'defaultCommandSequence'. In either case create your own object
    // of type 'sapbi_CommandSequence' that will be sent to the server.
    // To extract specific values of parameters refer to the following
    // snippet:
    //  var key = currentState.getParameter( PARAM_KEY ).getValue();
    //  alert( "Selected key: " + key );
    // ('PARAM_KEY' refers to any parameter's name)
    //Create a new object of type sapbi_CommandSequence
    var commandSequence = new sapbi_CommandSequence();
      * Create a new object of type sapbi_Command with the command named "SET_RESULT_VISIBILITY"
    var commandSET_RESULT_VISIBILITY_1 = new sapbi_Command( "SET_RESULT_VISIBILITY" );
    /* Create parameter TARGET_DATA_PROVIDER_REF_LIST */
    var paramTARGET_DATA_PROVIDER_REF_LIST = new sapbi_Parameter( "TARGET_DATA_PROVIDER_REF_LIST", "" );
    var paramListTARGET_DATA_PROVIDER_REF_LIST = new sapbi_ParameterList();
    // Create parameter TARGET_DATA_PROVIDER_REF
    var paramTARGET_DATA_PROVIDER_REF1 = new sapbi_Parameter( "TARGET_DATA_PROVIDER_REF", "DP_1" );
    paramListTARGET_DATA_PROVIDER_REF_LIST.setParameter( paramTARGET_DATA_PROVIDER_REF1, 1 );
      // End parameter TARGET_DATA_PROVIDER_REF!
    paramTARGET_DATA_PROVIDER_REF_LIST.setChildList( paramListTARGET_DATA_PROVIDER_REF_LIST );
    commandSET_RESULT_VISIBILITY_1.addParameter( paramTARGET_DATA_PROVIDER_REF_LIST );
    /* End parameter TARGET_DATA_PROVIDER_REF_LIST */
    /* Create parameter CHARACTERISTIC */
    var paramCHARACTERISTIC = new sapbi_Parameter( "CHARACTERISTIC", "0PROJECT" );
    commandSET_RESULT_VISIBILITY_1.addParameter( paramCHARACTERISTIC );
    /* End parameter CHARACTERISTIC */
    /* Create parameter RESULT_VISIBILITY */
    var paramRESULT_VISIBILITY = new sapbi_Parameter( "RESULT_VISIBILITY", "VISIBLE" );
    commandSET_RESULT_VISIBILITY_1.addParameter( paramRESULT_VISIBILITY );
    /* End parameter RESULT_VISIBILITY */
    // Add the command to the command sequence
    commandSequence.addCommand( commandSET_RESULT_VISIBILITY_1 );
      * End command commandSET_RESULT_VISIBILITY_1
    //Send the command sequence to the server
        return sapbi_page.sendCommand( commandSequence );

  • RMS help SOS

    Hi All,
    I wrote a semi-complete midlet that is supposed to have a datefield and textfield on a form. The contents of the datefield and textfield are supposed to be stored in 2 seperate recordstores when the user clicks the new command.
    Im using Wireless Toolkit 2.0 to compile and run the midlet. The problem right now is im getting the error:
    Unable to create MIDlet ToDoList
    java.lang.StringIndexOutOfBoundsException: String index out of range: 2
         at java.lang.String.substring(+29)
         at ToDoList.strToDate(+48)
         at ToDoList.<init>(+175)
         at java.lang.Class.runCustomCode(+0)
         at com.sun.midp.midlet.MIDletState.createMIDlet(+19)
         at com.sun.midp.midlet.Selector.run(+22)
    Im new to J2ME and hope to get some enlightenment here from you people. Thanks in advance for any help offered. Below is the code. Note that its not fully completed.
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.rms.*;
    import java.util.*;
    public class ToDoList extends MIDlet implements CommandListener
         private Command cmdMenu = new Command("Menu", Command.SCREEN, 1);
         private Command cmdPrev = new Command("Prev", Command.SCREEN, 2);
         private Command cmdNext = new Command("Next", Command.SCREEN, 3);
         private Command cmdNew = new Command("New", Command.SCREEN, 4);
         private Command cmdExit = new Command("Exit", Command.SCREEN, 5);
         private RecordStore rsDate = null;
         private RecordStore rsToDo = null;
         private Form frmMain;
         private Display display;
         private TextField tfToDo = new TextField("", "", 30, TextField.ANY);
         private DateField dfDate = new DateField("", DateField.DATE);
         private int recordID = 1;
         public ToDoList()
              try
                        rsToDo = RecordStore.openRecordStore("rsToDo", true);
                        rsDate = RecordStore.openRecordStore("rsDate", true);
                        String text = loadEntry(rsToDo.getNumRecords());
                        String strDate = loadDate(rsDate.getNumRecords());
                        Date date = strToDate(strDate);
                        dfDate.setDate(date);
                        tfToDo.setString(text);
                        frmMain = new Form("Entry " + recordID);
                   catch (RecordStoreException e)
                   throw new RuntimeException("Cannot open diary; reason: "+e);
                   frmMain.append(dfDate);
                   frmMain.append(tfToDo);
                   frmMain.addCommand(cmdPrev);
                   frmMain.addCommand(cmdNext);
                   frmMain.addCommand(cmdNew);
                   frmMain.addCommand(cmdExit);
                   frmMain.setCommandListener(this);
         public Date strToDate(String str)     //converts String to Date
              Calendar c = Calendar.getInstance();
              if(str == "")
                    c.set(Calendar.DAY_OF_MONTH, 1);
                    c.set(Calendar.YEAR, 1);
                    c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
                    c.set(Calendar.MONTH, Calendar.JANUARY);
                    Date rDate = c.getTime();
                    return rDate;
              else
                   String sDayOW = str.substring(0, 2);
                   String sMonth = str.substring(8, 10);
                   int iDay = Integer.valueOf(str.substring(5, 6)).intValue();
                   int iYear = Integer.valueOf(str.substring(12, 15)).intValue();
                   c.set(Calendar.DAY_OF_MONTH, iDay);
                   c.set(Calendar.YEAR, iYear);
                   if(sDayOW == "Mon")
                        c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
                   else if(sDayOW == "Tue")
                        c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
                        else if(sDayOW == "Wed")
                                  c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
                              else if(sDayOW == "Thu")
                                        c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
                                   else
                                        c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
                   if(sMonth == "Jan")
                        c.set(Calendar.MONTH, Calendar.JANUARY);
                   else if(sMonth == "Feb")
                             c.set(Calendar.MONTH, Calendar.FEBRUARY);
                        else if(sMonth == "Mar")
                                  c.set(Calendar.MONTH, Calendar.MARCH);
                             else if(sMonth == "Apr")
                                       c.set(Calendar.MONTH, Calendar.APRIL);
                                  else if(sMonth == "May")
                                            c.set(Calendar.MONTH, Calendar.MAY);
                                       else if(sMonth == "Jun")
                                                 c.set(Calendar.MONTH, Calendar.JUNE);
                                            else if(sMonth == "Jul")
                                                      c.set(Calendar.MONTH, Calendar.JULY);
                                                 else if(sMonth == "Aug")
                                                           c.set(Calendar.MONTH, Calendar.AUGUST);
                                                      else if(sMonth == "Sep")
                                                                c.set(Calendar.MONTH, Calendar.SEPTEMBER);
                                                           else if(sMonth == "Oct")
                                                                     c.set(Calendar.MONTH, Calendar.OCTOBER);
                                                                else if(sMonth == "Nov")
                                                                          c.set(Calendar.MONTH, Calendar.NOVEMBER);
                                                                     else
                                                                          c.set(Calendar.MONTH, Calendar.DECEMBER);
              Date rDate = c.getTime();
              return rDate;
         public String loadEntry(int iD) throws RecordStoreException
              //check if it is a new entry or the first entry to the diary, if it is, add a blank record to the diary
              if (iD < 1 || iD > rsToDo.getNumRecords())
                   byte [] data = " ".getBytes();
                   recordID = rsToDo.addRecord(data, 0, data.length);
                   return "";
              else     //else, get the record entry
                     recordID = iD;
                     return(new String(rsToDo.getRecord(recordID)));     //return the entry from the diary for the current record
         public String loadDate(int iD) throws RecordStoreException
              //check if it is a new entry or the first entry to the diary, if it is, add a blank record to the diary
              if (iD < 1 || iD > rsDate.getNumRecords())
                   byte [] data = " ".getBytes();
                   recordID = rsDate.addRecord(data, 0, data.length);
                   return "";
              else     //else, get the record entry
                     recordID = iD;
                     return(new String(rsDate.getRecord(recordID)));     //return the entry from the diary for the current record
         public void saveDate(String entry) throws RecordStoreException
                 //save the new entry to the diary
                 byte[] data = entry.getBytes();
              rsDate.setRecord(recordID, data, 0, data.length);
         public void saveEntry(String entry) throws RecordStoreException
                 //save the new entry to the diary
                 byte[] data = entry.getBytes();
              rsToDo.setRecord(recordID, data, 0, data.length);
         public void startApp()
              display = Display.getDisplay(this);
              display.setCurrent(frmMain);
         public void pauseApp()
         public void destroyApp(boolean unconditional)
              try
                  rsToDo.closeRecordStore();
                  rsDate.closeRecordStore();
              catch (RecordStoreException e)
                  throw new RuntimeException ("Cannot close RecordStore; reason: "+e);
         public void commandAction(Command c, Displayable d)
              if(c == cmdExit)
                   destroyApp(true);
                   notifyDestroyed();
              else if(c == cmdNew)
                        try
                             String strText;
                             String sDate;
                            strText = tfToDo.getString ();
                            sDate = String.valueOf(dfDate.getDate());
                            saveDate(sDate);
                            saveEntry(strText);
                            recordID = recordID + 1;
                              startApp();     
                       catch (RecordStoreException e)
                            throw new RuntimeException ("Cannot close Diary; reason: "+e);

    Nevermind, I found out what the error was. Is there anyway to edit messages on this forum?

Maybe you are looking for

  • Hp v235r flash drive not being detected on my computer

    Hi, I am using hp v235r flash drive for more than 5 years. It's not being detected on my computer since two days. Can any one solve my problem, as there is lot of important data stored in it and hasn't been backed up recently.

  • Counter in file name in receiver file adapter

    Hi, I am using FTP, my requirement is to add counter in the file name i.e XYZ001. And added to this i can increment the counter till XYZ020, after this i am supposed to start again from XYZ001.It will be some how handled that when i place XYZ001 for

  • During GR against Process Order Storage loc. not appearing

    He Experts, I am trying to do goods receipt against process order for bulk material using MIGO. But under where tab in MIGO storage loc field is not appearing. For this material production storage location is maintained in MRP2 view & in material typ

  • Premiere Pro 7.2.1 keeps crashing/corrupting projects

    Help -- First problem is that PP CC ver 7,2,1 keeps crashing, giving error reports that the project is "damaged or contains outdated elements."  It's ruined 2 projects in 2 days including the backup for one of them. I've cleaned the caches; deleted t

  • When I edit my emails, the delete option is no longer present.  No option is there at all?

    I used to be able to delete emails by hitting edit, checking the circle and then htting the delete button would remove those emails.  Now when I hit edit there are no options on the screen to delete, move archive or anything.  What am I missing? I ju