i know should use "actionlistener", suppose below code should work doesn't.
if (e.getsource() == "but0") { // but0 name of button number "0" string aaa = but0.gettext(); field.settext(aaa); }
add button in array when creating it
arraylist<jbutton> buttona = new arraylist(); for(int i=0;i<=9;i++) { string num_ = string.valueof(i); jbutton button = new jbutton(num_); button.setname(num_); buttona.add(button); // remaining stuff }
in action
public void actionperformed(actionevent e) { if(buttona.contains(e.getsource())) { jbutton btn = (jbutton) e.getsource(); display.settext(display.gettext() + btn.getname()); } else if() { // operations +,- etc., }
Comments
Post a Comment