[mobility] How to enter data using buttons in a textfield ..like 1+3 calculator application in lwuit

  • From: "nawaz" < >
  • To:
  • Subject: [mobility] How to enter data using buttons in a textfield ..like 1+3 calculator application in lwuit
  • Date: Sat, 29 Sep 2012 05:22:28 -0400

there is code below i want to enter data in a textfield like 1+4 using 
buttons......calculator application plz help


Code:



 

import com.sun.lwuit.Button;
 import com.sun.lwuit.Container;
 import com.sun.lwuit.Display;
 import com.sun.lwuit.Form;
 import com.sun.lwuit.Label;
 import com.sun.lwuit.TextField;
 import com.sun.lwuit.events.ActionEvent;
 import com.sun.lwuit.events.ActionListener;
 import com.sun.lwuit.geom.Dimension;
 import com.sun.lwuit.layouts.GridLayout;
 import com.sun.lwuit.layouts.Layout;
 import javax.microedition.midlet.MIDlet;
 
/**
 * @author Nawaz Baig
 */
 public class Midlet extends MIDlet implements ActionListener {
 
Button b1;
 Button b2;
 Button b3;
 Button b4;
 Button b5;
 Button b6;
 Button b7;
 Button b8;
 Button b9;
 
Button b10;
 
Button b11;
 
Button b12;
 
Button b13;
 
TextField my;
 Layout l;
 public void startApp() {
 Display.init(this);
 Form mainForm = new Form("Telculator");
 

my = new TextField("");
 
mainForm.setLayout(new GridLayout(3,3));
 b1= new Button("0");
 b2= new Button("1");
 b3= new Button("2");
 b4= new Button("3");
 b5= new Button("4");
 b6= new Button("5");
 b7= new Button("6");
 b8= new Button("7");
 b9= new Button("8");
 b10= new Button("9");
 b11=new Button("+");
 b12=new Button("=");
 b13 = new Button("Clear");
 


b1.addActionListener(this);
 b2.addActionListener(this);
 b3.addActionListener(this);
 b4.addActionListener(this);
 b5.addActionListener(this);
 b6.addActionListener(this);
 b7.addActionListener(this);
 b8.addActionListener(this);
 b9.addActionListener(this);
 b10.addActionListener(this);
 b11.addActionListener(this);
 b12.addActionListener(this);
 b13.addActionListener(this);
 
mainForm.addComponent(my);
 mainForm.addComponent(b1);
 mainForm.addComponent(b2);
 mainForm.addComponent(b3);
 mainForm.addComponent(b4);
 mainForm.addComponent(b5);
 mainForm.addComponent(b6);
 mainForm.addComponent(b7);
 mainForm.addComponent(b8);
 mainForm.addComponent(b9);
 mainForm.addComponent(b10);
 mainForm.addComponent(b11);
 mainForm.addComponent(b12);
 mainForm.addComponent(b13);
 mainForm.show();
 }
 
public void pauseApp() {
 }
 
public void destroyApp(boolean unconditional) {
 }
 
public void actionPerformed(ActionEvent ae) {
 
if(ae.getSource()==b1)
 {
 my.setT9Text("0");
 }
 if(ae.getSource()==b2)
 {
 my.setText("1");
 
}
 if(ae.getSource()==b3)
 {
 my.setText("2");
 
}
 if(ae.getSource()==b4)
 {
 my.setText("3");
 }
 if(ae.getSource()==b5)
 {
 my.setText("4");
 }
 
if(ae.getSource()==b6)
 {
 my.setText("5");
 }
 
if(ae.getSource()==b7)
 {
 my.setText("6");
 }
 
if(ae.getSource()==b8)
 {
 my.setText("7");
 

}
 

if(ae.getSource()==b9)
 {
 my.setText("8");
 
}
 
if(ae.getSource()==b10)
 {
 my.setText("9");
 
}
 

if(ae.getSource()==b11)
 {
 my.setText("+");
 }
 
if(ae.getSource()==b12)
 {
 int i = my.getText().indexOf("+");
 String before =my.getText().substring(0, i);
 String after =my.getText().substring(i,+1);
 

my.setText(Integer.parseInt(before)+Integer.parseI nt(after)+"" );
 }
 if(ae.getSource()==b13)
 {
 my.clear();
 }
 

}
 } 











[mobility] How to enter data using buttons in a textfield ..like 1+3 calculator application in lwuit

nawaz 09/29/2012

Project Features

About this Project

Mobility was started in November 2009, is owned by dstrupl, and has 36 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close