Hi, how to get the value printed in the button to appear in the text area that I have created, I have initialized text area and the buttons in lwuit.............................I have created the buttons by array................
Hi, how to get the value printed in the button to appear in the text area that I have created, I have initialized text area and the buttons in lwuit.............................I have created the buttons by array................
dont know so much about LWUIT but there must be some function to get String or label of command.. Check and verify..
look at this..
command.getName();
thanks,
jitu_goldie..
KEEP TRYING..
try getText() method of the button. If you are looking for the mechanism to press the button and set its value in a textarea , I think I've replied to you post on the same problem
http://discussion.forum.nokia.com/fo...y-one-help-me-.....................
To set value in a textarea , use setText() method of textArea.
Please elaborate your problem if still u dont get the solution.
Thanks.
Hi I am doing a calculator using lwuit wherein I have created the buttons and text area I wanna know how to display the value printed over the button to cum in textfield.......
I am able to get the properties of the button by the following statement
public void actionPerformed(ActionEvent ae)
{
//String numbers =("0123456789");
//String operations =("+-*/.");
//String Clear = "C";
if(ae.getSource() instanceof Command)
{
if(ae.getSource() == exit)
{
parentMidlet.notifyDestroyed();
}
}
if(ae.getSource() instanceof Button)
{
Button btn = (Button) ae.getSource();
//System.out.println(""+btns);
//txt.setText(numbers);
String S = btn.getText();
System.out.println("button is"+S);
}
}
hi I have created the buttons using a string array ...................so now thw value that is getting printed should cum in text area how to make it cum pls help me...........
Hi I have got that myself........................by the follwing command
if(ae.getSource() instanceof Button)
{
Button btn = (Button) ae.getSource();
//System.out.println(""+btns);
//txt.setText(numbers);
/* String button = btn.getText();*/
// System.out.println("button is"+button);
txt.setText(btn.getText());
}
now I wanna get continues values as u get it in calculator like 11,22,121 so on............................................................
So for this, in your actionPerformed()
if you get any operator don't append it to the text.
Thanks,
Ekta
hi I gave as
String numbers =("0123456789")
if(ae.getsource == numbers)
{
Button btn = (Button) ae.getSource();
txt.setText(btn.getText());
}
it doesnt stated any error but was not able to get the values in the text area it is not even evaluvating the if statement y wht might be the reason......................
This if(ae.getsource == numbers) will not work, comment it out.
update txt.setText(btn.getText()); with below
You will need to compare if( btn.getText() .equals("0")||btn.getText() .equals("1")||btn.getText() .equals("2")||btn.getText() .equals("3")||btn.getText() .equals("4")||btn.getText() .equals("5")||btn.getText() .equals("6")||btn.getText() .equals("7")||btn.getText() .equals("8")||btn.getText() .equals("8")) txt.setText(btn.getText());
Thanks,
Ekta
hi Ekta thank u I have seperated the numbers from the operators thank u for u help .............................................now for the operators I have given a if loop like urs
if(btn.getText().equals("+")||btn.getText().equals("-")||btn.getText().equals("*")||btn.getText().equals("/"))
{
doOperations();
}
which would call the doOperation method where I would define the +,- * / operations ..................k ekta its some personal oblication will u be online bcause if I have any doubt u can help me let me first define the doOperation method
Hi ekta can u help me how can I get the value when I press the = button c I have wrriten as follows
public void doOperations()
{
{
if(valueone.equals(""))
{
valueone = txt.getText();
operation = operand;
secondValueStarted = false;
}
if(operand.equals("="))
{
valuetwo = txt.getText();
if(operation.equals("+"))
{
float result = Float.parseFloat(valueone) + Float.parseFloat(valuetwo);
resetCalculator();
txt.setText(String.valueOf(result));
}
if(operation.equals("-"))
{
float result = Float.parseFloat(valueone) - Float.parseFloat(valuetwo);
resetCalculator();
txt.setText(String.valueOf(result));
}
if(operation.equals("*"))
{
float result = Float.parseFloat(valueone) * Float.parseFloat(valuetwo);
resetCalculator();
txt.setText(String.valueOf(result));
}
if(operation.equals("/"))
{
float result = Float.parseFloat(valueone) / Float.parseFloat(valuetwo);
resetCalculator();
txt.setText(String.valueOf(result));
}
}
}
}
and I have globally declared
protected String valueone="";
protected String valuetwo="";
protected String operation="";
please help me..............................