2023年12月21日发(作者:宝马m3图片)
android:id=\"@+id/btn_aliquot\" android:layout_width=\"0dp\" android:layout_height=\"70dp\" android:layout_column=\"2\" android:layout_weight=\"1\" android:text=\"%\" android:textColor=\"#ff0000\" android:textSize=\"12pt\" /> android:layout_height=\"70dp\" android:layout_column=\"0\" android:layout_weight=\"1\" android:text=\"1\" android:textSize=\"12pt\" />
Activicy代码:package culator;import patActivity;import t;import ;import ;import ;import ;import xt;import ;import ;public class MainActivity extends AppCompatActivity implements kListener{ /*按钮定义*/ Button btn_one; //1 Button btn_two; //2 Button btn_three; //3 Button btn_four; //4 Button btn_five; //5 Button btn_six; //6 Button btn_seven; //7 Button btn_eight; //8 Button btn_nine; //9 Button btn_zero; //0 Button btn_c; //c Button btn_ce; //ce Button btn_aliquot; //% Button btn_divide; //除号 Button btn_multiply;//x Button btn_subtract;//- Button btn_add; //+ Button btn_point; //. Button btn_equal; //= Button btn_leftBracket;//( Button btn_rightBracket;//) EditText contentBox; @Override protected void onCreate(Bundle savedInstanceState) { te(savedInstanceState); setContentView(ty_main); initControls(); initClickEvent(); } //找到控件 private void initControls() { btn_one = findViewById(_one); btn_two = findViewById(_two); btn_three = findViewById(_three); btn_four = findViewById(_four); btn_five = findViewById(_five); btn_six = findViewById(_six); btn_seven = findViewById(_seven); btn_eight = findViewById(_eight);
btn_nine = findViewById(_nine); btn_zero = findViewById(_zero); btn_c = findViewById(_c); btn_ce = findViewById(_ce); btn_aliquot = findViewById(_aliquot); btn_divide = findViewById(_divide); btn_multiply = findViewById(_multiply); btn_subtract = findViewById(_subtract); btn_add = findViewById(_add); btn_point = findViewById(_point); btn_equal = findViewById(_equal); contentBox = findViewById(t_box); btn_leftBracket = findViewById(_leftBracket); btn_rightBracket = findViewById(_rightBracket); } @Override public void onClick(View view) { switch (()){ case _one:{ changeVal(\"1\"); }break; case _two:{ changeVal(\"2\"); }break; case _three:{ changeVal(\"3\"); }break; case _four:{ changeVal(\"4\"); }break; case _five:{ changeVal(\"5\"); }break; case _six:{ changeVal(\"6\"); }break; case _seven:{ changeVal(\"7\"); }break; case _eight:{ changeVal(\"8\"); }break; case _nine:{ changeVal(\"9\"); }break; case _zero:{ changeVal(\"0\"); }break; case _aliquot:{ changeVal(\"%\"); }break; case _divide:{ changeVal(\"/\"); }break; case _multiply:{ changeVal(\"*\"); }break; case _subtract:{ changeVal(\"-\"); }break; case _add:{ changeVal(\"+\"); }break; case _rightBracket:{
changeVal(\")\"); }break; case _leftBracket:{ changeVal(\"(\"); }break; case _c:{ funC(); }break; case _ce:{ funClearAll(); }break; case _point:{ changeVal(\".\"); }break; case _equal:{ String str = t().toString(); Calculator calculator = new Calculator(); Double result = (str); t(ng()); }break; } } private void changeVal(String flag){ String str = t().toString(); t(str+flag); } private void funC(){ String str = t().toString(); str = ing(0,()-1); t(str); } private void funClearAll(){ t(\"\"); } private void initClickEvent(){ btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); btn_lickListener(this); }}计算表达式代码:package culator;import .*;
更多推荐
计算,表达式,小数点,图片,按钮,控件,作者,定义
发布评论