1   package counterWidgets;
2   
3   import javax.microedition.lcdui.Command;
4   import javax.microedition.lcdui.Item;
5   import javax.microedition.lcdui.ItemCommandListener;
6   import javax.microedition.lcdui.StringItem;
7   
8   /**
9    * Näppäin-luokka, jolta saadaan tapahtuma kun sitä painetaan.
10   * Käyttö:
11   * <pre>
12   *   Button nappain = new Button("Paina tätä");  form.append(nappain);
13   *   nappain.setItemCommandListener(this);
14   *   ...
15   *  public void commandAction(Command c, Item it) {
16   *    if ( it == nappain ) ... // tee mitä pitää tehdä näppäintä painettaessa
17   *  }
18   * </pre>
19   * @author vesal
20   * @version 17.3.2007
21   */
22  public class Button extends StringItem  implements ItemCommandListener {
23    public Button(String text) {
24      super(text,"",StringItem.BUTTON);
25      setLayout(LAYOUT_CENTER | LAYOUT_NEWLINE_BEFORE);
26      Command cmd = new Command(text,Command.SCREEN,2);
27      addCommand(cmd);
28      setDefaultCommand(cmd);
29      setItemCommandListener(this);
30    }
31    public void commandAction(Command c, Item it) {
32    }
33  }
34