admin 管理员组文章数量: 887021
2023年12月25日发(作者:数据库设计视图创建查询)
//效果图:
//java代码部分:
package ;
import ty;
import ;
import ;
import kListener;
import ;
import xt;
public class MainActivity extends Activity {
// 定义九个数字
private Button one;
private Button two;
private Button three;
private Button four;
private Button five;
private Button six;
private Button seven;
private Button eight;
private Button nine;
private Button zero;
private Button dot;
private Button add;
private Button sub;
private Button mul;
private Button div;
private Button clear;
private Button equal;
private EditText led;
String num1 = "";
String num2 = "";
double num3 = 0;
String result = "";
String sign = "+";
int mark = 0;
boolean flag = true;
boolean dotmark = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
te(savedInstanceState);
setContentView(ty_main);
zero = (Button) findViewById();
one = (Button) findViewById();
two = (Button) findViewById();
three = (Button) findViewById();
four = (Button) findViewById();
five = (Button) findViewById();
six = (Button) findViewById();
seven = (Button) findViewById();
eight = (Button) findViewById();
nine = (Button) findViewById();
add = (Button) findViewById();
sub = (Button) findViewById();
mul = (Button) findViewById();
div = (Button) findViewById();
clear = (Button) findViewById();
led = (EditText) findViewById();
equal = (Button) findViewById();
dot = (Button) findViewById();
lickListener(new OnClickListener() {
public void onClick(View v) {
if (mark == 0) {
num1 = num1 + "0";
t(num1);
} else if (mark == 1) {
num2 = num2 + "0";
t(num1 + sign + num2);
} else {
num1 = f(num3);
num2 = num2 + "0";
t(num1 + sign + num2);
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (mark == 0) {
num1 = num1 + "1";
t(num1);
} else if (mark == 1) {
num2 = num2 + "1";
t(num1 + sign + num2);
} else {
num1 = f(num3);
num2 = num2 + "1";
t(num1 + sign + num2);
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (mark == 0) {
num1 = num1 + "2";
t(num1);
} else if (mark == 1) {
num2 = num2 + "2";
t(num1 + sign + num2);
} else {
num1 = f(num3);
num2 = num2 + "2";
t(num1 + sign + num2);
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (mark == 0) {
num1 = num1 + "3";
t(num1);
} else if (mark == 1) {
num2 = num2 + "3";
t(num1 + sign + num2);
} else {
num1 = f(num3);
num2 = num2 + "3";
t(num1 + sign + num2);
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (mark == 0) {
num1 = num1 + "4";
t(num1);
} else if (mark == 1) {
num2 = num2 + "4";
t(num1 + sign + num2);
} else {
num1 = f(num3);
num2 = num2 + "4";
t(num1 + sign + num2);
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (mark == 0) {
num1 = num1 + "5";
t(num1);
} else if (mark == 1) {
num2 = num2 + "5";
t(num1 + sign + num2);
} else {
num1 = f(num3);
num2 = num2 + "5";
t(num1 + sign + num2);
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (mark == 0) {
num1 = num1 + "6";
t(num1);
} else if (mark == 1) {
num2 = num2 + "6";
t(num1 + sign + num2);
} else {
num1 = f(num3);
num2 = num2 + "6";
t(num1 + sign + num2);
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (mark == 0) {
num1 = num1 + "7";
t(num1);
} else if (mark == 1) {
num2 = num2 + "7";
t(num1 + sign + num2);
} else {
num1 = f(num3);
num2 = num2 + "7";
t(num1 + sign + num2);
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (mark == 0) {
num1 = num1 + "8";
t(num1);
} else if (mark == 1) {
num2 = num2 + "8";
t(num1 + sign + num2);
} else {
num1 = f(num3);
num2 = num2 + "8";
t(num1 + sign + num2);
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (mark == 0) {
num1 = num1 + "9";
t(num1);
} else if (mark == 1) {
num2 = num2 + "9";
t(num1 + sign + num2);
} else {
num1 = f(num3);
num2 = num2 + "9";
t(num1 + sign + num2);
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (flag) {
sign = "+";
mark++;
flag = false;
dotmark = true;
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (flag) {
sign = "-";
mark++;
flag = false;
dotmark = true;
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (flag) {
sign = "*";
mark++;
flag = false;
dotmark = true;
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (flag) {
sign = "÷";
mark++;
flag = false;
dotmark = true;
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
if (dotmark) {
if (mark == 0) {
num1 = num1 + ".";
t(num1);
} else if (mark == 1) {
num2 = num2 + ".";
t(num1 + sign + num2);
} else {
num1 = f(num3);
num2 = num2 + ".";
t(num1 + sign + num2);
}
dotmark = false;
}
}
});
lickListener(new OnClickListener() { // 等于时发生的运算
public void onClick(View v) {
flag = true;
dotmark = true;
if (("+")) {
double x = ouble(num1);
double y = ouble(num2);
num3 = x + y;
result = f(num3);
t(num1 + sign + num2 + "=" + result);
num2 = "";
} else if (("-")) {
double x = ouble(num1);
double y = ouble(num2);
num3 = x - y;
result = f(num3);
t(num1 + sign + num2 + "=" + result);
num2 = "";
} else if (("*")) {
double x = ouble(num1);
double y = ouble(num2);
num3 = x * y;
result = f(num3);
t(num1 + sign + num2 + "=" + result);
num2 = "";
} else if (("÷")) {
double x = ouble(num1);
double y = ouble(num2);
num3 = x / y;
result = f(num3);
t(num1 + sign + num2 + "=" + result);
num2 = "";
} else if (("^")) {
double x = ouble(num1);
double y = ouble(num2);
num3 = (x, y);
result = f(num3);
t(num1 + sign + num2 + "=" + result);
num2 = "";
}
}
});
lickListener(new OnClickListener() {
public void onClick(View v) {
num1 = "";
num2 = "";
num3 = 0;
mark = 0;
sign = "";
t("0");
flag = true;
dotmark = true;
}
});
}
}
Layout布局:
xmlns:android="/apk/res/android" xmlns:tools="/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > android:id="@+id/led" android:layout_width="288dp" android:layout_height="79dp" android:background="#000" android:gravity="top|right" android:text="0" android:textColor="#FFF" android:textSize="20pt" android:textStyle="bold" /> android:layout_width="288dp" android:layout_height="70dp" android:orientation="horizontal" > android:layout_width="288dp" android:layout_height="70dp" android:layout_marginTop="0.5dp" android:orientation="horizontal" > android:id="@+id/seven" android:layout_width="70dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#D1D2D5" android:text="7" /> android:id="@+id/eight" android:layout_width="70dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#D1D2D5" android:text="8" /> android:id="@+id/nine" android:layout_width="70dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#D1D2D5" android:text="9" /> android:id="@+id/mul" android:layout_width="70dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#f99011" android:text="×" /> android:layout_width="288dp" android:layout_height="70dp" android:layout_marginTop="0.5dp" android:orientation="horizontal" > android:id="@+id/four" android:layout_width="70dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#D1D2D5" android:text="4" /> android:id="@+id/five" android:layout_width="70dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#D1D2D5" android:text="5" /> android:id="@+id/six" android:layout_width="70dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#D1D2D5" android:text="6" /> android:id="@+id/sub" android:layout_width="70dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#f99011" android:text="-" /> android:layout_width="288dp" android:layout_height="70dp" android:layout_marginTop="0.5dp" android:orientation="horizontal" > android:id="@+id/one" android:layout_width="70dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#D1D2D5" android:text="1" /> android:id="@+id/two" android:layout_width="70dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#D1D2D5" android:text="2" /> android:id="@+id/three" android:layout_width="70dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#D1D2D5" android:text="3" /> android:id="@+id/add" android:layout_width="70dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#f99011" android:text="+" /> android:layout_width="288dp" android:layout_height="70dp" android:layout_marginTop="0.5dp" android:orientation="horizontal" > android:id="@+id/zero" android:layout_width="141.5dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#D1D2D5" android:text="0" /> android:id="@+id/dot" android:layout_width="69.5dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#D1D2D5" android:text="." /> android:id="@+id/equal" android:layout_width="68.5dp" android:layout_height="70dp" android:layout_margin="0.5dp" android:layout_weight="1" android:background="#f99011" android:onClick="enterInfo" android:text="=" />
版权声明:本文标题:安卓仿苹果计算器(内附完整源码) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1703472000h452839.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论