• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Adding button on a form

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the detailed reply. It solved my problem.
 
Always! Wait. Never. Shut up. Look at this tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic