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

📄 caculator_未解决十进制以外的数值输入和计算问题.java

📁 Java 语言实现的计算器
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                b_div.setText("<html><font color=red>/</font></html>");		b_deng = new JButton("=");                b_deng.setText("<html><font color=red>=</font></html>");		b_dian = new JButton(".");                b_dian.setText("<html><font color=blue>.</font></html>");		b_sign = new JButton("+/-");                b_sign.setText("<html><font color=blue>+/-</font></html>");		b_100 = new JButton("%");                b_100.setText("<html><font color=blue>%</font></html>");		b_dao = new JButton("1/x");                b_dao.setText("<html><font color=blue>1/x</font></html>");		b_sqrt = new JButton("sqrt");                b_sqrt.setText("<html><font color=blue>sqrt</font></html>");                Mod = new JButton("Mod");                Mod.setText("<html><font color=red>Mod</font></html>");                And = new JButton("And");                And.setText("<html><font color=red>And</font></html>");                Or = new JButton("Or");                Or.setText("<html><font color=red>Or</font></html>");                Xor = new JButton("Xor");                Xor.setText("<html><font color=red>Xor</font></html>");                Lsh = new JButton("Lsh");                Lsh.setText("<html><font color=red>Lsh</font></html>");                Not = new JButton("Not");                Not.setText("<html><font color=red>Not</font></html>");                Int = new JButton("Int");                A = new JButton("A");                B = new JButton("B");                C = new JButton("C");                D = new JButton("D");                E = new JButton("E");                F = new JButton("F");		                if (style == 2)                {                    panel3.setLayout(new GridLayout(5,6,3,2));                    panel3.add(b_7);  panel3.add(b_8);   panel3.add(b_9);   panel3.add(b_div);  panel3.add(Mod) ;   panel3.add(And);  		    panel3.add(b_4);  panel3.add(b_5);   panel3.add(b_6);   panel3.add(b_mul);  panel3.add(Or);     panel3.add(Xor);		    panel3.add(b_1);  panel3.add(b_2);   panel3.add(b_3);   panel3.add(b_sub);  panel3.add(Lsh);    panel3.add(Not);		    panel3.add(b_0);  panel3.add(b_sign);panel3.add(b_dian);panel3.add(b_add);  panel3.add(b_deng); panel3.add(Int);                    panel3.add(A);    panel3.add(B);     panel3.add(C);     panel3.add(D);      panel3.add(E);      panel3.add(F);                }                else                 {                       panel3.setLayout(new GridLayout(4,6,3,2));                    panel3.add(b_MC);  panel3.add(b_7);  panel3.add(b_8);   panel3.add(b_9);   panel3.add(b_div);  panel3.add(b_sqrt);		    panel3.add(b_MR);  panel3.add(b_4);  panel3.add(b_5);   panel3.add(b_6);   panel3.add(b_mul);panel3.add(b_100);		    panel3.add(b_MS);  panel3.add(b_1);  panel3.add(b_2);   panel3.add(b_3);   panel3.add(b_sub);  panel3.add(b_dao);		    panel3.add(b_Madd);panel3.add(b_0);  panel3.add(b_sign);panel3.add(b_dian);panel3.add(b_add);  panel3.add(b_deng);                                }                                panel.setLayout(flow);                panel4 = new JPanel();                                if (style==2)		{				panel4.setLayout(new GridLayout(5,4,3,2));                		b_xy = new JButton("x^y");                b_xy.setText("<html><font color=purple>x^y</font></html>");		b_ln = new JButton("ln");                b_ln.setText("<html><font color=purple>ln</font></html>");		b_log = new JButton("log");                b_log.setText("<html><font color=purple>log</font></html>");		b_pi = new JButton("pi");                b_pi.setText("<html><font color=blue>pi</font></html>");		b_x2 = new JButton("x^2");                b_x2.setText("<html><font color=purple>x^2</font></html>");		b_x3 = new JButton("x^3");                b_x3.setText("<html><font color=purple>x^3</font></html>");		b_k1 = new JButton("(");                b_k1.setText("<html><font color=purple>(</font></html>");		b_k2 = new JButton(")");                b_k2.setText("<html><font color=purple>)</font></html>");		b_sin = new JButton("sin");                b_sin.setText("<html><font color=purple>sin</font></html>");		b_cos = new JButton("cos");                b_cos.setText("<html><font color=purple>cos</font></html>");		b_tan = new JButton("tan");                b_tan.setText("<html><font color=purple>tan</font></html>");		b_n = new JButton("n!");                b_n.setText("<html><font color=purple>n!</font></html>");                b_FE = new JButton("F-E");                b_FE.setText("<html><font color=purple>F-E</font></html>");		b_dms = new JButton("dms");                b_dms.setText("<html><font color=purple>dms</font></html>");		b_Exp = new JButton("Exp");                b_Exp.setText("<html><font color=purple>Exp</font></html>");                b_dao.setText("<html><font color=purple>1/x</font></html>");                b_Sta = new JButton("Sta");                b_Sta.setText("<html><font color=blue>Sta</font></html>");                		panel4.add(b_FE);  panel4.add(b_k1);  panel4.add(b_k2); panel4.add(b_MC);		panel4.add(b_dms);  panel4.add(b_Exp);  panel4.add(b_ln); panel4.add(b_MR);		panel4.add(b_sin);  panel4.add(b_xy);  panel4.add(b_log); panel4.add(b_MS);		panel4.add(b_cos);  panel4.add(b_x3);  panel4.add(b_n);   panel4.add(b_Madd);                panel4.add(b_tan);  panel4.add(b_x2);  panel4.add(b_dao); panel4.add(b_pi);                                panel52 = new JPanel();                panel52.setLayout(new GridLayout(5,1,3,2));                panel52.add(b_Sta);                panel52.add(b_Ave);                panel52.add(b_Sum);                panel52.add(b_s);                panel52.add(b_Dat);                                panel.add(panel52);                panel.add(Null4);                panel.add(panel4);                panel.add(Null3);				A.setEnabled(false);                B.setEnabled(false);                C.setEnabled(false);                D.setEnabled(false);                E.setEnabled(false);                F.setEnabled(false);			}                		panel.add(panel3);		basebox.add(panel);		//添加键盘事件		addKeyListener(this);		//给按钮添加监听器,监听事件		b_Backspace.addActionListener(this);b_Backspace.addKeyListener(this);		b_CE.addActionListener(this);b_CE.addKeyListener(this);		b_C.addActionListener(this);b_C.addKeyListener(this);		b_MC.addActionListener(this);b_MC.addKeyListener(this);		b_MR.addActionListener(this);b_MR.addKeyListener(this);		b_MS.addActionListener(this);b_MS.addKeyListener(this);		b_Madd.addActionListener(this);b_Madd.addKeyListener(this);		b_0.addActionListener(this);b_0.addKeyListener(this);		b_1.addActionListener(this);b_1.addKeyListener(this);		b_2.addActionListener(this);b_2.addKeyListener(this);		b_3.addActionListener(this);b_3.addKeyListener(this);		b_4.addActionListener(this);b_4.addKeyListener(this);		b_5.addActionListener(this);b_5.addKeyListener(this);		b_6.addActionListener(this);b_6.addKeyListener(this);		b_7.addActionListener(this);b_7.addKeyListener(this);		b_8.addActionListener(this);b_8.addKeyListener(this);		b_9.addActionListener(this);b_9.addKeyListener(this);		b_add.addActionListener(this);b_add.addKeyListener(this);		b_sub.addActionListener(this);b_sub.addKeyListener(this);		b_mul.addActionListener(this);b_mul.addKeyListener(this);		b_div.addActionListener(this);b_div.addKeyListener(this);		b_dian.addActionListener(this);b_dian.addKeyListener(this);		b_sign.addActionListener(this);b_sign.addKeyListener(this);		b_sqrt.addActionListener(this);b_sqrt.addKeyListener(this);		b_100.addActionListener(this);b_100.addKeyListener(this);		b_deng.addActionListener(this);b_deng.addKeyListener(this);		b_dao.addActionListener(this);b_dao.addKeyListener(this);		if(style == 2)                {                b_pi.addActionListener(this);b_pi.addKeyListener(this);		b_k1.addActionListener(this);b_k1.addKeyListener(this);		b_k2.addActionListener(this);b_k2.addKeyListener(this);		b_xy.addActionListener(this);b_xy.addKeyListener(this);		b_x2.addActionListener(this);b_x2.addKeyListener(this);		b_x3.addActionListener(this);b_x3.addKeyListener(this);		b_sin.addActionListener(this);b_sin.addKeyListener(this);		b_cos.addActionListener(this);b_cos.addKeyListener(this);		b_tan.addActionListener(this);b_tan.addKeyListener(this);		b_n.addActionListener(this);b_n.addKeyListener(this);		b_ln.addActionListener(this);b_ln.addKeyListener(this);		b_log.addActionListener(this);b_log.addKeyListener(this);                A.addActionListener(this);A.addKeyListener(this);                B.addActionListener(this);B.addKeyListener(this);                C.addActionListener(this);C.addKeyListener(this);                D.addActionListener(this);D.addKeyListener(this);                E.addActionListener(this);E.addKeyListener(this);                F.addActionListener(this);F.addKeyListener(this);                b_FE.addActionListener(this);b_FE.addKeyListener(this);                b_dms.addActionListener(this);b_dms.addKeyListener(this);                b_Exp.addActionListener(this);b_Exp.addKeyListener(this);                               }		//**************------底层添加布局-------***************		Container con = getContentPane();		con.setLayout(new FlowLayout());		con.add(basebox);				validate();		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);	}	//*************----------相关方法-----------***************	void input(String s)//输入数字的函数	{			if (start==0)			{				t[state]=s;				start=1;			}			else			{				t[state]=t_show.getText()+s;			}                        //String ame = Integer.valueOf("t[state]",16).toString();			t_show.setText(t[state]);                        //d[state]=Double.parseDouble(t[state]);//这一句该怎么改?				}	void clear()//清楚当前状态	{		t[state]="0"; d[state]=0; start=0;	}	String n(String s)//计算阶乘	{		BigInteger ss=new BigInteger(s);		BigInteger result=new BigInteger("1"),r=new BigInteger("1"),re=new BigInteger("1");		while(re.compareTo(ss)<0)		{            re=re.add(r);			result=result.multiply(re);		}		return result.toString();	}	double op(double x)//三角函数结果处理	{		int z=(int)(x*1000000);		if(z%10>=5)			z=z+10-z%10;		return (double)z/1000000;	}	void done()//进行运算的函数	{		deng=1;		switch(marks[mark])		{			case 1:				d[2*mark-1]=d[2*mark-1]+d[2*mark];				t[2*mark-1]=String.valueOf(d[2*mark-1]);				t_show.setText(t[2*mark-1]);				break;			case 2:				d[2*mark-1]=d[2*mark-1]-d[2*mark];				t[2*mark-1]=String.valueOf(d[2*mark-1]);				t_show.setText(t[2*mark-1]);				break;			case 3:				d[2*mark-1]=d[2*mark-1]*d[2*mark];				t[2*mark-1]=String.valueOf(d[2*mark-1]);				t_show.setText(t[2*mark-1]);				break;			case 4:				if(d[2*mark]==0)				{					t_show.setText("除数不能为0");					start=0;					break;				}				d[2*mark-1]=d[2*mark-1]/d[2*mark];				t[2*mark-1]=String.valueOf(d[2*mark-1]);				t_show.setText(t[2*mark-1]);				break;			case 5:				d[state]=Math.pow(d[state-1],d[state]);				t[state]=String.valueOf(d[state]);				t_show.setText(t[state]);			default:				break;		}	}		//*************----------相关事件-----------***************	public void actionPerformed(ActionEvent e)	{		//菜单条内的按钮事件#######################################                                if(e.getSource() == hex)//十六进制按钮显示                {                    A.setEnabled(true);                    B.setEnabled(true);                    C.setEnabled(true);                    D.setEnabled(true);                    E.setEnabled(true);                    F.setEnabled(true);                    b_8.setEnabled(true);                    b_9.setEnabled(true);                    b_7.setEnabled(true);                    b_6.setEnabled(true);                    b_5.setEnabled(true);                    b_4.setEnabled(true);                    b_3.setEnabled(true);                    b_2.setEnabled(true);                A.setText("<html><font color=blue>A</font></html>");                B.setText("<html><font color=blue>B</font></html>");                C.setText("<html><font color=blue>C</font></html>");                D.setText("<html><font color=blue>D</font></html>");                E.setText("<html><font color=blue>E</font></html>");                F.setText("<html><font color=blue>F</font></html>");                b_8.setText("<html><font color=blue>8</font></html>");                b_9.setText("<html><font color=blue>9</font></html>");                b_7.setText("<html><font color=blue>7</font></html>");                b_6.setText("<html><font color=blue>6</font></html>");                b_5.setText("<html><font color=blue>5</font></html>");                b_4.setText("<html><font color=blue>4</font></html>");                b_3.setText("<html><font color=blue>3</font></html>");                b_2.setText("<html><font color=blue>2</font></html>");                    b_FE.setEnabled(false);                    b_dms.setEnabled(false);                    b_Exp.setEnabled(false);                    b_sin.setEnabled(false);                    b_cos.setEnabled(false);                    b_tan.setEnabled(false);                    b_pi.setEnabled(false);                b_sin.setText("<html><font color=gray>sin</font></html>");

⌨️ 快捷键说明

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