String button_name[][]={
{"1","2","3","+"},
{"4","5","6","-"},
{"7","8","9","*"},
{".","0","=","/"}
};
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
c.gridx = j; c.gridy = i+1;
makebutton(button_name[i][j],gridbag,c);
}
}
}
private class SimpleListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String buttonName = e.getActionCommand();
char key = buttonName.charAt(0);
/******************************************************************************/
if(key=='.'){
if(textfield.getText().indexOf(".")==-1){
if(last_in!=none){
if(last_in=='+' || last_in=='-' || last_in=='*' || last_in=='/'){
last_flag=last_in;
a = new BigDecimal(textfield.getText());
textfield.setText("");
}
}
textfield.setText(textfield.getText()+buttonName);
}
}
else if(key>='0' && key<='9'){
if(last_in!=none){
if(last_in=='='){
a = zero;
last_flag= none;
textfield.setText("");
}
else if(last_in=='+' || last_in=='-' || last_in=='*' || last_in=='/'){
last_flag=last_in;
a = new BigDecimal(textfield.getText());
textfield.setText("");
}
}
last_in=key;
textfield.setText(textfield.getText()+buttonName);
}
else if(key=='+' || key=='-' || key=='*' || key=='/' || key=='='){
if(last_in>='0' && last_in<='9' || last_in=='='){
if(last_flag!=none){
tmp = new BigDecimal(textfield.getText());
switch(last_flag){
case '+':a=a.add(tmp);break;
case '-':a=a.subtract(tmp);break;
case '*':a=a.multiply(tmp);break;
case '/':