没有合适的资源?快使用搜索试试~ 我知道了~
用java编写的一个计算器
资源详情
资源评论
资源推荐
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
//import java.math.*;
public class cal extends Applet
{
//定义所有需要使用的全局变量
String str="0";//暂存显示屏数据
String sign="null";//暂存符号数据
double num=0;//暂存内部运算数据
boolean change=false;//暂存内部四则运算起用
GridLayout g0,g1;//定义 AWT 布局部件
JTextField number;
Button num_p,num_0,num_1,num_2,num_3,num_4,num_5,num_6,num_7,num_8,num_9;
Button act_add,act_mul,act_div,act_sub;
Button mat_sin,mat_cos,mat_tan;
Button do_ans,do_del;
Panel p0,p1;
public void init()//主程序部分
{
//定义各个控件的样式
number=new JTextField(20);//显示屏
number.setHorizontalAlignment(JTextField.RIGHT);
number.setEnabled(false);
number.setText("0");
num_p=new Button("。");//小数点的按钮
num_p.setForeground(Color.red);
num_p.addActionListener(new getbt());
num_0=new Button("0");//数字 0 的按钮
num_0.setForeground(Color.red);
num_0.addActionListener(new getbt());
num_1=new Button("1");//数字 1 的按钮
num_1.setForeground(Color.red);
num_1.addActionListener(new getbt());
num_2=new Button("2");//数字 2 的按钮
num_2.setForeground(Color.red);
num_2.addActionListener(new getbt());
num_3=new Button("3");//数字 3 的按钮
num_3.setForeground(Color.red);
num_3.addActionListener(new getbt());
num_4=new Button("4");//数字 4 的按钮
num_4.setForeground(Color.red);
num_4.addActionListener(new getbt());
num_5=new Button("5");//数字 5 的按钮
num_5.setForeground(Color.red);
num_5.addActionListener(new getbt());
num_6=new Button("6");//数字 6 的按钮
num_6.setForeground(Color.red);
num_6.addActionListener(new getbt());
num_7=new Button("7");//数字 7 的按钮
num_7.setForeground(Color.red);
num_7.addActionListener(new getbt());
num_8=new Button("8");//数字 8 的按钮
num_8.setForeground(Color.red);
num_8.addActionListener(new getbt());
num_9=new Button("9");//数字 9 的按钮
num_9.setForeground(Color.red);
num_9.addActionListener(new getbt());
act_add=new Button("+");//加法的按钮
act_add.setForeground(Color.red);
act_add.addActionListener(new getbt());
act_sub=new Button("-");//减法的按钮
act_sub.setForeground(Color.red);
act_sub.addActionListener(new getbt());
act_mul=new Button("*");//乘法的按钮
act_mul.setForeground(Color.red);
act_mul.addActionListener(new getbt());
act_div=new Button("/");//除法的按钮
act_div.setForeground(Color.red);
act_div.addActionListener(new getbt());
do_ans=new Button("=");//等于的按钮
do_ans.setForeground(Color.red);
do_ans.addActionListener(new getbt());
do_del=new Button("del");//等于的按钮
do_del.setForeground(Color.red);
do_del.addActionListener(new getbt());
mat_sin=new Button("sin");//sin 的按钮
mat_sin.setForeground(Color.red);
mat_sin.addActionListener(new getbt());
mat_cos=new Button("cos");//cos 的按钮
mat_cos.setForeground(Color.red);
mat_cos.addActionListener(new getbt());
mat_tan=new Button("tan");//tan 的按钮
mat_tan.setForeground(Color.red);
mat_tan.addActionListener(new getbt());
//布局整个计算器
g0=new GridLayout(1,1,10,10);//布局输入输出大体位置
g1=new GridLayout(4,5,10,10);
p0=new Panel(); //显示屏的布局
p0.setLayout(g0);
p0.add(number);
p0.setBounds(0,0,100,50);
//按纽的布局
p1=new Panel();
p1.setLayout(g1);
p1.add(num_1);//第一排按纽
p1.add(num_2);
p1.add(num_3);
p1.add(act_add);
p1.add(act_sub);
p1.add(num_4);//第二排按纽
剩余11页未读,继续阅读
唯米独帅
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0