用JAVA编写一个计算器完成简单的加法、减法、除法和乘法操作-查字典问答网
分类选择

来自梁平凡的问题

  用JAVA编写一个计算器完成简单的加法、减法、除法和乘法操作.RT

  用JAVA编写一个计算器完成简单的加法、减法、除法和乘法操作.

  RT

1回答
2020-09-08 02:06
我要回答
请先登录
孙傲冰

  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");//等于

2020-09-08 02:08:46

最新问答

推荐文章

猜你喜欢

附近的人在看

推荐阅读

拓展阅读

  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  •