Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

j2ME: Problem changing the value of an integer or string

 
Sangeeta Vepa
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want to change the value of a string or integer which was declared at the top. I have initialized it in the constructor.
Now, i want to change its value when a button is pressed. Say "Next" or "Prev" and call repaint(). But i m unable to get the changed value.
Let me tell u why i need this:
I need to use a variable as a flag just to know that the particular button is pressed and execute some code in the paint method depending on the changed value received from the variable.
Basically, i want the prb to print "Next" when "next" button is pressed and to print "Prev" when "prev" is pressed.
Where am i doing wrong ... Please specify. Is there any problem in the place where i am initializing the integer or string.
import javax.microedition.midlet.*;
import java.lang.*;
import javax.microedition.lcdui.*;
import java.util.*;
import java.io.*;
/**
*
* @author SangeetaV
* @version
*/
public class ReportScreen extends Canvas implements CommandListener {
public String inextvalue;
private Command nextCommand;
private Command prevCommand;

public ReportScreen(VKJNewOrder midlet){

inextvalue = new String("abcd");
nextCommand = new Command("Next", Command.OK, 3);
prevCommand = new Command("Prev", Command.OK, 3);
this.addCommand(nextCommand);
this.addCommand(prevCommand);
this.setCommandListener(this);

}
protected void paint( Graphics g )
{
System.out.println("This is inextvalue : " + inextvalue);
}
public void commandAction(Command c, Displayable s)
{
if (c == nextCommand)
{
inextvalue = "Next";
this.repaint();
}
else if(c == prevCommand)
{
inextvalue = "Prev";
this.repaint();
}
}
}
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see the string but where's the integer?
 
Sangeeta Vepa
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lasse,
I am saying i declared it as a flag to check whether "Next" button is pressed or "Prev" button is pressed. So, here either String or Integer flag can be taken. Both are not required.
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic