⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 至强计算器.txt

📁 用JAVA编写的计算器
💻 TXT
📖 第 1 页 / 共 3 页
字号:
 我前段时间在这里发布了一个java计算器,近期多人询问,我再这里再放一个0.4版的计算器,可以直接运行  发表时间: 2004-07-24 22:28    
 
//用文本编辑器建立文件Calc.java把以下代码拷入,存盘后用命令javac Calc.java编译成Calc.class文件,然后用命令java Calc即可
//design by SunYi and YangShangYing
//my email footballreg@sohu.com
//my phone 13611152520
//Calculator 0.4

import java.awt.*;
import java.awt.event.*;
import java.math.*;
import java.lang.*;


public class Calc extends WindowAdapter implements ActionListener,KeyListener{
    
    //result变量保存计算的结果,data1保存当前正在输入的数字(是一个浮点的数字,并不仅仅指键盘上的某个数字键),radixPointDepth保存当前输入的数字是小数点后的第几位,他由radixPointIndicate控制是否起作用
     private double result=0,data1=0,radixPointDepth=1,memData=0;
    
    //radixPointIndicate记录小数点是否被按下,被按下后为true,equalSignPressIndicate记录上一次控制键是否为等号,为等号则为true,numberPressIndicate记录上一次按得是否为数字(包括.号),是为true,memDataIndicate记录内存中是否有数据,有为true
     private boolean radixPointIndicate=false,equalSignPressIndicate=false,numberPressIndicate=false,memDataIndicate=false;
     
     private String s;
     private char prec='+';
    private Frame f;
    private TextField tf;
    private Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31,b32,b33,b34,b35,b36,b37,b38,b39,b40,b41,b42,b43,b44,b45,b46,b47,b48,b49,b50,b51,b52,b53,b54;
    private Panel p,pScientific,pAngle;
    private CheckboxGroup angle;
    private Checkbox degrees,radians,grads;
    private Color blue,red,gold;
    private Double displayNumber=new Double(data1);

   
    static public void main(String args[]){
       
        Calc de=new Calc();
        de.go();
    }

    public void go(){
            
        //下面为界面的生成部分
        
        Color blue=new Color(0,0,255);
          Color red=new Color(150,0,0);
          Color green=new Color(0,255,0);
          Color gold=new Color(255,215,0);
        Color orange=new Color(255,165,0);
        Color white=new Color(255,255,255);
        Color black=new Color(50,50,50);
        
          Color DeepSkyBlue3=new Color(0,154,205);        
        Color NavyBlue=new Color(0,0,128);
        
        Color DarkGreen=new Color(0,100,0);
        
        Color snow1=new Color(255,250,250);
        Color snow2=new Color(238,233,233);
        Color snow3=new Color(205,201,201);
        Color red1=new Color(220,0,0);
        
          Font font1=new Font("TimesRoman",Font.BOLD,18);
          Font font2=new Font("SansSerif",Font.PLAIN,14);            
                
        //生成主框架
        f=new Frame("JavaCalculator 0.4 by SunYang");
        tf=new TextField("0.0",30);
        pAngle=new Panel();
        p=new Panel();        
        
        f.add(tf,"North");
          f.add(p,"Center");
          f.add(pAngle,"South");
        
        GridLayout gridLayout1=new GridLayout(9,6);
        gridLayout1.setHgap(0);
        gridLayout1.setVgap(0);
        p.setLayout(gridLayout1);
        
        //生成一般计算器界面
        

        
    
        

          

          tf.setFont(font1);
          p.setFont(font2);
                                          

          tf.setEditable(false);
          
      
        b1=new Button("Back");
        b2=new Button("CE");
          b3=new Button(" ");
          b4=new Button(" ");
          b5=new Button("C");
           b6=new Button("OFF");
          b7=new Button("7");
          b8=new Button("8");
          b9=new Button("9");
          b10=new Button("/");
           b11=new Button("sqrt");
          b12=new Button("MC");
          b13=new Button("4");
          b14=new Button("5");
           b15=new Button("6");
           b16=new Button("*");
          b17=new Button("%");
          b18=new Button("MR");
          b19=new Button("1");
          b20=new Button("2");
          b21=new Button("3");
          b22=new Button("-");
          b23=new Button("1/x");
          b24=new Button("MS");
          b25=new Button("0");
          b26=new Button("+/-");
          b27=new Button(".");
          b28=new Button("+");
          b29=new Button("=");
          b30=new Button("M+");
          p.add(b1);
          p.add(b2);
          p.add(b3);
          p.add(b4);
          p.add(b5);
          p.add(b6);
          p.add(b7);
          p.add(b8);
          p.add(b9);
          p.add(b10);
          p.add(b11);
          p.add(b12);
          p.add(b13);
          p.add(b14);
          p.add(b15);
          p.add(b16);
          p.add(b17);
          p.add(b18);
          p.add(b19);
          p.add(b20);
          p.add(b21);
          p.add(b22);
          p.add(b23);
          p.add(b24);
          p.add(b25);
          p.add(b26);
          p.add(b27);
          p.add(b28);
          p.add(b29);
          p.add(b30);

        f.addKeyListener(this);
        p.addKeyListener(this);
        tf.addKeyListener(this);
        b1.addKeyListener(this);
          b2.addKeyListener(this);
          b3.addKeyListener(this);
          b4.addKeyListener(this);
          b5.addKeyListener(this);
          b6.addKeyListener(this);
          b7.addKeyListener(this);
          b8.addKeyListener(this);
          b9.addKeyListener(this);
          b10.addKeyListener(this);
          b11.addKeyListener(this);
          b12.addKeyListener(this);
          b13.addKeyListener(this);
          b14.addKeyListener(this);
          b15.addKeyListener(this);
          b16.addKeyListener(this);
          b17.addKeyListener(this);
          b18.addKeyListener(this);
          b19.addKeyListener(this);
          b20.addKeyListener(this);
          b21.addKeyListener(this);
          b22.addKeyListener(this);
          b23.addKeyListener(this);
          b24.addKeyListener(this);
          b25.addKeyListener(this);
          b26.addKeyListener(this);
          b27.addKeyListener(this);
          b28.addKeyListener(this);
          b29.addKeyListener(this);
          b30.addKeyListener(this);
          b1.addActionListener(this);
          b2.addActionListener(this);
          b3.addActionListener(this);
          b4.addActionListener(this);
          b5.addActionListener(this);
          b6.addActionListener(this);
          b7.addActionListener(this);
          b8.addActionListener(this);
          b9.addActionListener(this);
          b10.addActionListener(this);
          b11.addActionListener(this);
          b12.addActionListener(this);
          b13.addActionListener(this);
          b14.addActionListener(this);
          b15.addActionListener(this);
          b16.addActionListener(this);
          b17.addActionListener(this);
          b18.addActionListener(this);
          b19.addActionListener(this);
          b20.addActionListener(this);
          b21.addActionListener(this);
          b22.addActionListener(this);
          b23.addActionListener(this);
          b24.addActionListener(this);
          b25.addActionListener(this);
          b26.addActionListener(this);
          b27.addActionListener(this);
          b28.addActionListener(this);
          b29.addActionListener(this);
          b30.addActionListener(this);
          
                    
          //生成科学计算器界面
          b31=new Button("hyp");
          b32=new Button("sin");
          b33=new Button("cos");
          b34=new Button("tan");
          b35=new Button("F-E");
           b36=new Button("n!");
          b37=new Button("DEG");
          b38=new Button("ln");
          b39=new Button("log");
          b40=new Button("a");
           b41=new Button("b");
          b42=new Button("->");
          b43=new Button("exp");
          b44=new Button("y^x");
           b45=new Button("x^-2");
           b46=new Button("x^2");
          b47=new Button("(");
          b48=new Button(")");
          b49=new Button("A");
          b50=new Button("B");
          b51=new Button("C");
          b52=new Button("D");
          b53=new Button("E");
          b54=new Button("F");
          
        
          b31.addActionListener(this);
          b32.addActionListener(this);
          b33.addActionListener(this);
          b34.addActionListener(this);
          b35.addActionListener(this);
          b36.addActionListener(this);
          b37.addActionListener(this);
          b38.addActionListener(this);
          b39.addActionListener(this);
          b40.addActionListener(this);
          b41.addActionListener(this);
          b42.addActionListener(this);
          b43.addActionListener(this);
          b44.addActionListener(this);
          b45.addActionListener(this);
          b46.addActionListener(this);
          b47.addActionListener(this);
          b48.addActionListener(this);
          b49.addActionListener(this);
          b50.addActionListener(this);
          b51.addActionListener(this);
          b52.addActionListener(this);
          b53.addActionListener(this);
          b54.addActionListener(this);
          
          b31.addKeyListener(this);
          b32.addKeyListener(this);
          b33.addKeyListener(this);
          b34.addKeyListener(this);
          b35.addKeyListener(this);
          b36.addKeyListener(this);
          b37.addKeyListener(this);
          b38.addKeyListener(this);
          b39.addKeyListener(this);
          b40.addKeyListener(this);
          b41.addKeyListener(this);
          b42.addKeyListener(this);
          b43.addKeyListener(this);
          b44.addKeyListener(this);
          b45.addKeyListener(this);
          b46.addKeyListener(this);
          b47.addKeyListener(this);
          b48.addKeyListener(this);
          b49.addKeyListener(this);
          b50.addKeyListener(this);
          b51.addKeyListener(this);
          b52.addKeyListener(this);
          b53.addKeyListener(this);
          b54.addKeyListener(this);
          p.add(b31);
          p.add(b32);
          p.add(b33);
          p.add(b34);
          p.add(b35);
          p.add(b36);
          p.add(b37);
          p.add(b38);
          p.add(b39);
          p.add(b40);
          p.add(b41);
          p.add(b42);
          p.add(b43);
          p.add(b44);
          p.add(b45);
          p.add(b46);
          p.add(b47);
          p.add(b48);
          p.add(b49);
          p.add(b50);
          p.add(b51);
          p.add(b52);
          p.add(b53);
          p.add(b54);
          
          //角度弧度和梯度的选择
        angle=new CheckboxGroup();
        degrees=new Checkbox("degrees",angle,true);
        radians=new Checkbox("radians",angle,false);
        grads=new Checkbox("grads",angle,false);
        pAngle.add(degrees);
        pAngle.add(radians);
        pAngle.add(grads);



        
        //整个计算器的frame的设置
        f.addWindowListener(this);        
        f.setSize(300,280);
        f.setVisible(true);
          //f.pack();
          
          

          tf.setBackground(snow1);
          
          b1.setBackground(black);
          b2.setBackground(black);
          b3.setBackground(black);
          b4.setBackground(black);          
          b5.setBackground(red1);
          b6.setBackground(red1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -