import java.awt.Button;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.List;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.math.BigDecimal;
import static java.awt.BorderLayout.*;
public class jisuan {
static String value = "0";
static StringBuffer temp = new StringBuffer("");
static String optValue = "0";
static String optType = "";
static boolean isChoiseOptType = true;
static TextField textField = new TextField(30);
static Button[] b = new Button[18];
public static void main(String[] args) {
class Li implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(b[0])) {
temp.append(b[0].getLabel());
textField.setText(temp.toString());
isChoiseOptType = false;
} else if (e.getSource().equals(b[1])) {
temp.append(b[1].getLabel());
textField.setText(temp.toString());
isChoiseOptType = false;
} else if (e.getSource().equals(b[2])) {
temp.append(b[2].getLabel());
textField.setText(temp.toString());
isChoiseOptType = false;
} else if (e.getSource().equals(b[3])) {
temp.append(b[3].getLabel());
textField.setText(temp.toString());
isChoiseOptType = false;
} else if (e.getSource().equals(b[4])) {
temp.append(b[4].getLabel());
textField.setText(temp.toString());
isChoiseOptType = false;
} else if (e.getSource().equals(b[5])) {
temp.append(b[5].getLabel());
textField.setText(temp.toString());
isChoiseOptType = false;
} else if (e.getSource().equals(b[6])) {
temp.append(b[6].getLabel());
textField.setText(temp.toString());
isChoiseOptType = false;
} else if (e.getSource().equals(b[7])) {
temp.append(b[7].getLabel());
textField.setText(temp.toString());
isChoiseOptType = false;
} else if (e.getSource().equals(b[8])) {
temp.append(b[8].getLabel());
textField.setText(temp.toString());
isChoiseOptType = false;
} else if (e.getSource().equals(b[9])) {
temp.append(b[9].getLabel());
textField.setText(temp.toString());
isChoiseOptType = false;
} else if (e.getSource().equals(b[14])) {
if (temp.length() <= 0)
temp.append("0");
temp.append(b[14].getLabel());
textField.setText(temp.toString());
isChoiseOptType = false;
} else if (e.getSource().equals(b[10])) {
if (!isChoiseOptType) {
value = textField.getText();
if (value.lastIndexOf(".") == value.length() - 1) {
value = value.substring(0, value.length() - 1);
}
optValue = value;
temp = new StringBuffer("");
}
optType = b[10].getLabel();
isChoiseOptType = true;
} else if (e.getSource().equals(b[11])) {
if (!isChoiseOptType) {
value = textField.getText();
if (value.lastIndexOf(".") == value.length() - 1) {
value = value.substring(0, value.length() - 1);
}
optValue = value;
temp = new StringBuffer("");
}
optType = b[11].getLabel();
isChoiseOptType = true;
} else if (e.getSource().equals(b[12])) {
if (!isChoiseOptType) {
value = textField.getText();
if (value.lastIndexOf(".") == value.length() - 1) {
value = value.substring(0, value.length() - 1);
}
optValue = value;
temp = new StringBuffer("");
}
optType = b[12].getLabel();
isChoiseOptType = true;
} else if (e.getSource().equals(b[13])) {
if (!isChoiseOptType) {
value = textField.getText();
if (value.lastIndexOf(".") == value.length() - 1) {
value = value.substring(0, value.length() - 1);
}
optValue = value;
temp = new StringBuffer("");
}
optType = b[13].getLabel();
isChoiseOptType = true;
} else if (e.getSource().equals(b[15])) {
if (!optType.equals("")) {
BigDecimal opt1 = new BigDecimal(optValue);
value = textField.getText();
if (value.lastIndexOf(".") == value.length() - 1) {
value = value.substring(0, value.length() - 1);
}
BigDecimal opt2 = new BigDecimal(value);
BigDecimal result = new BigDecimal(0);
if (optType.equals("+")) {
result = opt1.add(opt2);
} else if (optType.equals("-")) {
result = opt1.subtract(opt2);
} else if (optType.equals("*")) {
result = opt1.multiply(opt2);
} else if (optType.equals("/")) {
result = opt1.divide(opt2);
} else if (optType.equals("%")) {
result = opt1.remainder(opt2);
}
textField.setText(result.toString());
temp = new StringBuffer("");
isChoiseOptType = false;
optValue = "0";
}
}else if (e.getSource().equals(b[16])) {
temp=new StringBuffer();
textField.setText("0");
}
}// actioner
}// class li
Frame f = new Frame("计算器");
Panel p1 = new Panel();
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
p1.add(textField);
f.add(p1, NORTH);
Panel p2 = new Panel();
p2.setLayout(new GridLayout(3, 5, 4, 4));
String[] name = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"+", "-", "*", "/", ".", "=" ,"c"}; // 0 1 2 3 4 5 6 7 8 9 10 11 12
// 13 14 15
Li f1 = new Li();
for (int i = 0; i < name.length; i++) {
b[i] = new Button(name[i]);
p2.add(b[i]);
}
for (int i = 0; i < name.length; i++) {
b[i].addActionListener(f1);
}
f.add(p2);
f.pack();
f.setVisible(true);
}// public void main
}
没有合适的资源?快使用搜索试试~ 我知道了~
100多道关于C语言的练习答案,原题可以在OJ上找到
共138个文件
cpp:119个
html:9个
jpg:5个
5星 · 超过95%的资源 需积分: 48 40 下载量 89 浏览量
2013-03-13
17:49:32
上传
评论 5
收藏 653KB RAR 举报
温馨提示
100多道关于C语言的练习答案,原题可以在OJ上找到,都是我自己做,通过OJ系统检验
资源推荐
资源详情
资源评论
收起资源包目录
100多道关于C语言的练习答案,原题可以在OJ上找到 (138个子文件)
二叉树!!!!!!!.cpp 6KB
合并.cpp 4KB
顺序表比较.cpp 4KB
删除重复结点.cpp 3KB
顺序表.cpp 3KB
单链合并,逆置.cpp 3KB
单链合并.cpp 3KB
Message Decowding a.cpp 3KB
Lucky Letter a!!!.cpp 3KB
栈迷宫.cpp 2KB
顺序栈,数制转换算法1.cpp 2KB
第几天a!!!!!!!.cpp 2KB
链队.cpp 2KB
DS1线性表 a.cpp 2KB
顺序队.cpp 2KB
顺序栈.cpp 2KB
链栈.cpp 2KB
DS10 二项展开式的系数 a.cpp 1KB
队迷宫.cpp 1KB
DS24 二叉树2.cpp 1KB
DS12 队列模拟 a.cpp 1KB
队列打印杨辉3角.cpp 1KB
人见人爱A+Ba.cpp 1KB
Fibonacci数列a.cpp 1KB
DS22 稀疏矩阵的转置 a.cpp 1KB
DS7 TRANSFORMERS a.cpp 1KB
字符串判等 a.cpp 1KB
ASCII码排序a!!!!!!.cpp 1KB
三角矩阵a.cpp 1KB
QQ飞车a.cpp 986B
水仙花数a.cpp 966B
DS15 字符串匹配(1) a.cpp 953B
WERTYU a.cpp 917B
简单编码a.cpp 898B
DS4 并集 a.cpp 886B
运费a.cpp 820B
Alice做算术(1)a.cpp 792B
数列有序a.cpp 764B
Keep on Trucking .cpp 740B
蟠桃记a.cpp 722B
查找最大元素a.cpp 660B
矩阵加减法(1)a.cpp 647B
矩阵乘法 a.cpp 643B
C语言合法标识符a.cpp 627B
顺序后移a.cpp 623B
big big tree!!!!!!!.cpp 620B
DS4 交集 a.cpp 617B
DS19 对称矩阵 a.cpp 615B
亲和数a.cpp 594B
兑换硬币a.cpp 586B
u Calculate e a.cpp 576B
what day is today a.cpp 572B
回文a.cpp 563B
发工资啦a.cpp 558B
补考??a.cpp 555B
Calculated Prime Number a.cpp 553B
偶数求和a.cpp 533B
杨辉三角a.cpp 489B
汉字统计.cpp 489B
北岭山a.cpp 488B
查找a.cpp 468B
成绩转换a.cpp 464B
绝对值排序a.cpp 463B
简单统计a.cpp 448B
Alice做算术(2)a.cpp 447B
Above Average a.cpp 442B
整数求和a.cpp 434B
素数再判定a.cpp 430B
排序输出a.cpp 430B
最大公约数、最小公倍数a.cpp 427B
THE DRUNK JAILER a.cpp 420B
首字母变大写a.cpp 419B
打印三角形a.cpp 414B
多项式求和a.cpp 407B
数据的交换输出a.cpp 401B
数值统计a.cpp 394B
三角形面积a.cpp 384B
se7en a.cpp 374B
平方和与立方和a.cpp 369B
字母转换a.cpp 366B
菱形a.cpp 365B
矩阵各列元素之和a.cpp 351B
完数a.cpp 349B
青年歌手大奖赛_评委会打分a.cpp 333B
Fibonacci数列的4种求法之二 递推a.cpp 332B
数组,数制转换.cpp 328B
Alice数数 a.cpp 328B
素数的判断a!!!!!.cpp 325B
a的b次幂和b的a次幂a.cpp 325B
那个灯 a.cpp 322B
闰土a.cpp 319B
西方人的姓氏a.cpp 301B
递归计算式子.cpp 296B
n钱买n鸡a.cpp 268B
Hangover a.cpp 265B
让我们来扮演高斯a.cpp 264B
致命百分比a.cpp 263B
Financial Management a.cpp 257B
计算两点间的距离a.cpp 253B
No Brainer a.cpp 250B
共 138 条
- 1
- 2
资源评论
- 孤儿仔_2013-12-27很好,多数都有用~!~!~!
a156435646
- 粉丝: 1
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功