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

Adding button on a form

 
Ali Kiyani
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to develop a simple calculator. I am using a Form and over it I will place buttons like 1, 2, 3....
I tried to use Command to add buttons on form but got compile error. Here is the code:



Seems like a Command can't be placed on a form so how do I add buttons?
 
Ian Strain
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is no buttons in the same way as on windows applications etc.
If you want to use commands you have to add them to the form using Form.addCommand()
This will add the command buttons but will place them under the softkeys and if you have more than 2 commands they will be placed in a menu bar accessed by one of the softkeys

If its a calculator you are planning on making which is going to resemble a calculator like the one in windows then you are going to find it very difficult. This is because the lcdui, is very poor in organising layout. You may need to use a canvas and implement your own ui.

But if you want a button added to your form then you can use either an ImageItem (which would probably be best in your case) or a StringItem.
When you declare wither one, set the apperanceMode parameter to either Image Item.BUTTON or StringItem.BUTTON, depending on which you use.



You will have to have a command already declared and set it to be the default command of the ImageItem or StringItem


These items are now commands so in order for your code to recognise an event when they are pressed you must set an ItemCommandListener to the StringItem or ImageItem



you will have to implement the commandAction(Command command, Item item) method when implementing the ItemCommandListener. This gets called when you select the button item.
 
Ali Kiyani
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the detailed reply. It solved my problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic