当前位置:首页 » 操作系统 » c计算器源码

c计算器源码

发布时间: 2022-02-28 14:41:40

㈠ win7自带计算器的源代码

win7在运行处 输入calc.exe,可以直接进如计算器!

㈡ c++计算器源代码

#include<iostream>//简单的计算器
using namespace std;//DEV c++
int main()
{
int a,b;
char c;//这里变量名只能为char
cout<<"计算器"<<endl;
cout<<"你想使用哪种计算器(+,-,*,/)"<<endl;
cin>>c;
switch(c)//这里是对+,-,*,/进行使用(c)
{
case '+'://加法运算
{
cout<<"请输入第一个数"<<endl;
cin>>a;
cout<<"请输入第二个数"<<endl;
cin>>b;
cout<<a<<"+"<<b<<"="<<a+b;
}
break;//break是终止
case '-'://减法运算
{
cout<<"请输入第一个数"<<endl;
cin>>a;
cout<<"请输入第二个数"<<endl;
cin>>b;
cout<<a<<"-"<<b<<"="<<a-b;
}
break;
case '*'://乘法运算
{
cout<<"请输入第一个数"<<endl;
cin>>a;
cout<<"请输入第二个数"<<endl;
cin>>b;
cout<<a<<"*"<<b<<"="<<a*b;
}
break;
case '/'://除法运算
{
cout<<"请输入第一个数"<<endl;
cin>>a;
cout<<"请输入第二个数"<<endl;
cin>>b;
if(b!=0)
{
cout<<a<<"/"<<b<<"="<<a/b;
}
else cout<<"除数不能为0"<<endl;
}
break;
default:cout<<"请输入正确的运算符号"<<endl;//特殊情况
}
return 0;
}

㈢ 如何查看电脑上某程序的源代码 如计算器

可以通过GitHub源代码ping在计算机中检查计算器的源代码。具体操作方式如下:

1、进入GitHub的Microsoft个人问题主页,如下图所示。

(3)c计算器源码扩展阅读:

GitHub的Windows应用

GitHub 使用 git 分布式版本控制系统,而 git 最初是 LinusTorvalds 为帮助Linux开发而创造的,它针对的是 Linux 平台,因此 git 和 Windows 从来不是最好的朋友,因为它一点也不像Windows。

GitHub 发布了GitHub for Windows,为 Windows 平台开发者提供了一个易于使用的 Git 图形客户端。

GitHub forWindows是一个 Metro 风格应用程序,集成了自包含版本的 Git,bash 命令行 shell,PowerShell 的 posh-git 扩展。

GitHub 为 Windows 用户提供了一个基本的图形前端去处理大部分常用版本控制任务,可以创建版本库,向本地版本库递交补丁,在本地和远程版本库之间同步。微软也通过CodePlex向开发者提供 git 版本控制系统,而 GitHub 创造了一个更具有吸引力的 Windows 版本。

㈣ 求C++编写的科学计算器源代码

给你个地址,自己去下载。
★★[源码库]811款导弹-制导-弹道-惯性导航-GPS-雷达等仿真源代码★★
http://bbs.81tech.com/read.php?tid=209564

其中有两款计算机源代码:
1. 科学计算器程序--VC++源代码.rar (30 K)
2. 非常实用的一款计算器-VC++源代码.rar (138 K)

㈤ 关于java做的计算器源代码

关于计算器的设计其实是一个很大的学问,如果你按照严格的设计来完成一个计算器的话,完成之后。你就是一个很牛的人了。注意我说的是很牛
关于这方面的资料我建议你看本书
《大话设计模式》
这本书就是从计算器来展开的设计模式的运用和讲解

c语言计算器程序源代码

栈操作~
输入的弄成字符串。
如:a+(b+c*(d+e))
先检索“(”入栈,b入栈,+入栈,c入栈,*入栈,后面的不是数字那么“(”入栈,+,入栈,e入栈,
“)”入栈,遇到“)”,出栈操作,直到遇到第一个“(”。
得到字符:d+e,通过算法计算出值D,然后把D入栈。那么栈中的字符为:a+(b+c*D
向后判断一步看是不是乘或除,不是继续向后入栈,是就出栈。
得到c*D,通过算法计算值为C,入栈,那么栈中的字符为:a+(b+C,向后判断,无乘或除运算,继续入栈:“)”,遇到“)”,出栈操作,直到遇到第一个“(”,得到字符串:b+c,算法计算值为B,入栈
栈中字符串为:a+B 字符串结束,出栈操作计算出a+B,值。
如果字符串的式子很长的话,就反复的入栈出栈计算。
思路是这样的......
关于COS,SIN类的关键字,也是上面的思路,
(入栈,直到遇到)出栈,先计算出括号里的,然后后退一步判断前面的是乘除或者关键字,
如:sin(0.1+0.2)
操作得出sin0.3然后判断前面的是不是关键字,是那句计算sin0.3。
但是遇到关键字的时候不是一个一个字符在一起的,你可以入栈的时候判断是不是字母,是字母,那么入栈直到不是字母为止,出栈判断关键字也是一样......
不明白的继续问~

㈦ C#计算器源代码

全部按钮的事件代码可以省略成1个方法
private void Btn_click(object sender, EventArgs e)
{
//(button)sender,把sender参数强制转换成按钮类型,根据按钮的文本属性判断是哪个按钮
string buttonType= ((button)sender).Text;
}

㈧ 计算器源代码

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* 一个计算器,与Windows附件自带计算器的标准版功能、界面相仿。
* 但还不支持键盘操作。
*/
public class Calculator extends JFrame implements ActionListener {
/** 计算器上的键的显示名字 */
private final String[] KEYS = { "7", "8", "9", "/", "sqrt", "4", "5", "6",
"*", "%", "1", "2", "3", "-", "1/x", "0", "+/-", ".", "+", "=" };
/** 计算器上的功能键的显示名字 */
private final String[] COMMAND = { "Backspace", "CE", "C" };
/** 计算器左边的M的显示名字 */
private final String[] M = { " ", "MC", "MR", "MS", "M+" };
/** 计算器上键的按钮 */
private JButton keys[] = new JButton[KEYS.length];
/** 计算器上的功能键的按钮 */
private JButton commands[] = new JButton[COMMAND.length];
/** 计算器左边的M的按钮 */
private JButton m[] = new JButton[M.length];
/** 计算结果文本框 */
private JTextField resultText = new JTextField("0");

// 标志用户按的是否是整个表达式的第一个数字,或者是运算符后的第一个数字
private boolean firstDigit = true;
// 计算的中间结果。
private double resultNum = 0.0;
// 当前运算的运算符
private String operator = "=";
// 操作是否合法
private boolean operateValidFlag = true;
/**
* 构造函数
*/
public Calculator(){
super();
//初始化计算器
init();
//设置计算器的背景颜色
this.setBackground(Color.LIGHT_GRAY);
this.setTitle("计算器");
//在屏幕(500, 300)坐标处显示计算器
this.setLocation(500, 300);
//不许修改计算器的大小
this.setResizable(false);
//使计算器中各组件大小合适
this.pack();
}
/**
* 初始化计算器
*/
private void init() {
// 文本框中的内容采用右对齐方式
resultText.setHorizontalAlignment(JTextField.RIGHT);
// 不允许修改结果文本框
resultText.setEditable(false);
// 设置文本框背景颜色为白色
resultText.setBackground(Color.WHITE);

//初始化计算器上键的按钮,将键放在一个画板内
JPanel calckeysPanel = new JPanel();
//用网格布局器,4行,5列的网格,网格之间的水平方向间隔为3个象素,垂直方向间隔为3个象素
calckeysPanel.setLayout(new GridLayout(4, 5, 3, 3));
for (int i = 0; i < KEYS.length; i++) {
keys[i] = new JButton(KEYS[i]);
calckeysPanel.add(keys[i]);
keys[i].setForeground(Color.blue);
}
//运算符键用红色标示,其他键用蓝色表示
keys[3].setForeground(Color.red);
keys[8].setForeground(Color.red);
keys[13].setForeground(Color.red);
keys[18].setForeground(Color.red);
keys[19].setForeground(Color.red);

//初始化功能键,都用红色标示。将功能键放在一个画板内
JPanel commandsPanel = new JPanel();
//用网格布局器,1行,3列的网格,网格之间的水平方向间隔为3个象素,垂直方向间隔为3个象素
commandsPanel.setLayout(new GridLayout(1, 3, 3, 3));
for (int i = 0; i < COMMAND.length; i++) {
commands[i] = new JButton(COMMAND[i]);
commandsPanel.add(commands[i]);
commands[i].setForeground(Color.red);
}

//初始化M键,用红色标示,将M键放在一个画板内
JPanel calmsPanel = new JPanel();
//用网格布局管理器,5行,1列的网格,网格之间的水平方向间隔为3个象素,垂直方向间隔为3个象素
calmsPanel.setLayout(new GridLayout(5, 1, 3, 3));
for (int i = 0; i < M.length; i++) {
m[i] = new JButton(M[i]);
calmsPanel.add(m[i]);
m[i].setForeground(Color.red);
}

//下面进行计算器的整体布局,将calckeys和command画板放在计算器的中部,
//将文本框放在北部,将calms画板放在计算器的西部。

//新建一个大的画板,将上面建立的command和calckeys画板放在该画板内
JPanel panel1 = new JPanel();
//画板采用边界布局管理器,画板里组件之间的水平和垂直方向上间隔都为3象素
panel1.setLayout(new BorderLayout(3, 3));
panel1.add("North", commandsPanel);
panel1.add("Center", calckeysPanel);

//建立一个画板放文本框
JPanel top = new JPanel();
top.setLayout(new BorderLayout());
top.add("Center", resultText);

//整体布局
getContentPane().setLayout(new BorderLayout(3, 5));
getContentPane().add("North", top);
getContentPane().add("Center", panel1);
getContentPane().add("West", calmsPanel);
//为各按钮添加事件侦听器
//都使用同一个事件侦听器,即本对象。本类的声明中有implements ActionListener
for (int i = 0; i < KEYS.length; i++) {
keys[i].addActionListener(this);
}
for (int i = 0; i < COMMAND.length; i++) {
commands[i].addActionListener(this);
}
for (int i = 0; i < M.length; i++) {
m[i].addActionListener(this);
}
}

/**
* 处理事件
*/
public void actionPerformed(ActionEvent e) {
//获取事件源的标签
String label = e.getActionCommand();
if (label.equals(COMMAND[0])){
//用户按了"Backspace"键
handleBackspace();
} else if (label.equals(COMMAND[1])) {
//用户按了"CE"键
resultText.setText("0");
} else if (label.equals(COMMAND[2])){
//用户按了"C"键
handleC();
} else if ("0123456789.".indexOf(label) >= 0) {
//用户按了数字键或者小数点键
handleNumber(label);
// handlezero(zero);
} else {
//用户按了运算符键
handleOperator(label);
}
}
/**
* 处理Backspace键被按下的事件
*/
private void handleBackspace() {
String text = resultText.getText();
int i = text.length();
if (i > 0) {
//退格,将文本最后一个字符去掉
text = text.substring(0, i - 1);
if (text.length() == 0) {
//如果文本没有了内容,则初始化计算器的各种值
resultText.setText("0");
firstDigit = true;
operator = "=";
} else {
//显示新的文本
resultText.setText(text);
}
}
}

/**
* 处理数字键被按下的事件
* @param key
*/
private void handleNumber(String key) {
if (firstDigit) {
//输入的第一个数字
resultText.setText(key);
} else if ((key.equals(".")) && (resultText.getText().indexOf(".") < 0)){
//输入的是小数点,并且之前没有小数点,则将小数点附在结果文本框的后面
resultText.setText(resultText.getText() + ".");
} else if (!key.equals(".")) {
//如果输入的不是小数点,则将数字附在结果文本框的后面
resultText.setText(resultText.getText() + key);
}
//以后输入的肯定不是第一个数字了
firstDigit = false;
}
/**
* 处理C键被按下的事件
*/
private void handleC() {
//初始化计算器的各种值
resultText.setText("0");
firstDigit = true;
operator = "=";
}

/**
* 处理运算符键被按下的事件
* @param key
*/
private void handleOperator(String key) {
if (operator.equals("/")) {
//除法运算
//如果当前结果文本框中的值等于0
if (getNumberFromText() == 0.0){
//操作不合法
operateValidFlag = false;
resultText.setText("除数不能为零");
} else {
resultNum /= getNumberFromText();
}
} else if (operator.equals("1/x")) {
//倒数运算
if (resultNum == 0.0){
//操作不合法
operateValidFlag = false;
resultText.setText("零没有倒数");
} else {
resultNum = 1 / resultNum;
}
} else if (operator.equals("+")){
//加法运算
resultNum += getNumberFromText();
} else if (operator.equals("-")){
//减法运算
resultNum -= getNumberFromText();
} else if (operator.equals("*")){
//乘法运算
resultNum *= getNumberFromText();
} else if (operator.equals("sqrt")) {
//平方根运算
resultNum = Math.sqrt(resultNum);
} else if (operator.equals("%")){
//百分号运算,除以100
resultNum = resultNum / 100;
} else if (operator.equals("+/-")){
//正数负数运算
resultNum = resultNum * (-1);
} else if (operator.equals("=")){
//赋值运算
resultNum = getNumberFromText();
}
if (operateValidFlag) {
//双精度浮点数的运算
long t1;
double t2;
t1 = (long) resultNum;
t2 = resultNum - t1;
if (t2 == 0) {
resultText.setText(String.valueOf(t1));
} else {
resultText.setText(String.valueOf(resultNum));
}
}
//运算符等于用户按的按钮
operator = key;
firstDigit = true;
operateValidFlag = true;
}

/**
* 从结果文本框中获取数字
* @return
*/
private double getNumberFromText() {
double result = 0;
try {
result = Double.valueOf(resultText.getText()).doubleValue();
} catch (NumberFormatException e){
}
return result;
}

public static void main(String args[]) {
Calculator calculator1 = new Calculator();
calculator1.setVisible(true);
calculator1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

㈨ 求计算器源代码

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace jisuan
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(24, 72);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 21);
this.textBox1.TabIndex = 0;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(312, 72);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 21);
this.textBox2.TabIndex = 1;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(448, 72);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(88, 21);
this.textBox3.TabIndex = 2;
//
// comboBox1
//
this.comboBox1.Items.AddRange(new object[] {
"+",
"-",
"*",
"/"});
this.comboBox1.Location = new System.Drawing.Point(152, 72);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 3;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// button1
//
this.button1.Location = new System.Drawing.Point(64, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 32);
this.button1.TabIndex = 4;
this.button1.Text = "计算";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(216, 192);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 5;
this.button2.Text = "清除";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(376, 192);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 6;
this.button3.Text = "退出";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(656, 366);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public double jia(double a,double b)
{
return a+b;
}
public double jian(double a,double b)
{
return a-b;
}
public double cheng(double a,double b)
{
return a*b;
}
public double chu(double a,double b)
{
return a/b;
}

private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{

}

private void textBox1_TextChanged(object sender, System.EventArgs e)
{

}

private void button1_Click(object sender, System.EventArgs e)
{
string i=this.comboBox1.SelectedItem.ToString();

switch(i)
{

case "+":this.textBox3.Text=this.jia(double.Parse(this.textBox1.Text),double.Parse(this.textBox2.Text)).ToString();

break;

case "-":this.textBox3.Text=this.jian(double.Parse(this.textBox1.Text),double.Parse(this.textBox2.Text)).ToString();
break;
case "*":this.textBox3.Text=this.cheng(double.Parse(this.textBox1.Text),double.Parse(this.textBox2.Text)).ToString();
break;
case"/" :this.textBox3.Text=this.chu(double.Parse(this.textBox1.Text),double.Parse(this.textBox2.Text)).ToString();
break;
}

}

private void button2_Click(object sender, System.EventArgs e)
{
this.textBox1.Text=null;
this.textBox2.Text=null;
this.textBox3.Text = null;
}

private void button3_Click(object sender, EventArgs e)
{

//this.Hide();
Application.Exit();
//this.Close();

}
}
}
是否可以解决您的问题?

㈩ 简单计算器的源代码

package calculator;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.SystemColor;
import java.awt.Color;

/**
* <p>Title:</p>
*
* <p>Description: 这个类用来实现一个简单的计算器</p>
*
* <p>Copyright: Copyright (c) 2006年</p>
*
* <p>Company: </p>
*
* @author
* @version 1.0
*/
public class CalculatorFrame extends JFrame {

boolean flag = false;
String operand1;
String operand2;
double result;
String action;

BorderLayout borderLayout1 = new BorderLayout();
JTextField txtresult = new JTextField();
JButton btn1 = new JButton();
JButton btn2 = new JButton();
JButton btn3 = new JButton();
JButton btn4 = new JButton();
JButton btn5 = new JButton();
JButton btn6 = new JButton();
JButton btn7 = new JButton();
JButton btn8 = new JButton();
JButton btn9 = new JButton();
JButton btn0 = new JButton();
JButton btnplus = new JButton();
JButton btnminus = new JButton();
JButton btnjultiply = new JButton();
JButton btndivide = new JButton();
JButton btnclear = new JButton();
JButton btnequal = new JButton();

public CalculatorFrame() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}

private void jbInit() throws Exception {
getContentPane().setLayout(null);
txtresult.setBackground(SystemColor.WHITE);
txtresult.setBorder(BorderFactory.createLoweredBevelBorder());
txtresult.setDisabledTextColor(Color.black);
txtresult.setEditable(false);
txtresult.setHorizontalAlignment(JTextField.RIGHT);
txtresult.setBounds(new Rectangle(50, 50, 305, 25));
btn1.setBounds(new Rectangle(50, 200, 65, 30));
btn1.setBorder(BorderFactory.createRaisedBevelBorder());
btn1.setText("1");
btn1.addActionListener(new CalculatorFrame_btn1_actionAdapter(this));
btn2.setBounds(new Rectangle(130, 200, 65, 30));
btn2.setBorder(BorderFactory.createRaisedBevelBorder());
btn2.setText("2");
btn2.addActionListener(new CalculatorFrame_btn2_actionAdapter(this));
btn3.setBounds(new Rectangle(210, 200, 65, 30));
btn3.setBorder(BorderFactory.createRaisedBevelBorder());
btn3.setText("3");
btn3.addActionListener(new CalculatorFrame_btn3_actionAdapter(this));
btn4.setBounds(new Rectangle(50, 150, 65, 30));
btn4.setBorder(BorderFactory.createRaisedBevelBorder());
btn4.setText("4");
btn4.addActionListener(new CalculatorFrame_btn4_actionAdapter(this));
btn5.setBounds(new Rectangle(130, 150, 65, 30));
btn5.setBorder(BorderFactory.createRaisedBevelBorder());
btn5.setText("5");
btn5.addActionListener(new CalculatorFrame_btn5_actionAdapter(this));
btn6.setBounds(new Rectangle(210, 150, 65, 30));
btn6.setBorder(BorderFactory.createRaisedBevelBorder());
btn6.setText("6");
btn6.addActionListener(new CalculatorFrame_btn6_actionAdapter(this));
btn7.setBounds(new Rectangle(50, 100, 65, 30));
btn7.setBorder(BorderFactory.createRaisedBevelBorder());
btn7.setText("7");
btn7.addActionListener(new CalculatorFrame_btn7_actionAdapter(this));
btn8.setBounds(new Rectangle(130, 100, 65, 30));
btn8.setBorder(BorderFactory.createRaisedBevelBorder());
btn8.setText("8");
btn8.addActionListener(new CalculatorFrame_btn8_actionAdapter(this));
btn9.setBounds(new Rectangle(210, 100, 65, 30));
btn9.setBorder(BorderFactory.createRaisedBevelBorder());
btn9.setText("9");
btn9.addActionListener(new CalculatorFrame_btn9_actionAdapter(this));
btn0.setBounds(new Rectangle(50, 250, 65, 30));
btn0.setBorder(BorderFactory.createRaisedBevelBorder());
btn0.setText("0");
btn0.addActionListener(new CalculatorFrame_btn0_actionAdapter(this));
btnplus.setBounds(new Rectangle(290, 250, 65, 30));
btnplus.setBorder(BorderFactory.createRaisedBevelBorder());
btnplus.setText("+");
btnplus.addActionListener(new CalculatorFrame_btnplus_actionAdapter(this));
btnminus.setBounds(new Rectangle(290, 200, 65, 30));
btnminus.setBorder(BorderFactory.createRaisedBevelBorder());
btnminus.setText("-");
btnminus.addActionListener(new CalculatorFrame_btnminus_actionAdapter(this));
btnjultiply.setBounds(new Rectangle(290, 150, 65, 30));
btnjultiply.setBorder(BorderFactory.createRaisedBevelBorder());
btnjultiply.setText("*");
btnjultiply.addActionListener(new
CalculatorFrame_btnjultiply_actionAdapter(this));
btndivide.setBounds(new Rectangle(290, 100, 65, 30));
btndivide.setBorder(BorderFactory.createRaisedBevelBorder());
btndivide.setText("/");
btndivide.addActionListener(new CalculatorFrame_btndivide_actionAdapter(this));
btnclear.setBounds(new Rectangle(130, 250, 65, 30));
btnclear.setBorder(BorderFactory.createRaisedBevelBorder());
btnclear.setText("C");
btnclear.addActionListener(new CalculatorFrame_btnclear_actionAdapter(this));
btnequal.setBounds(new Rectangle(210, 250, 65, 30));
btnequal.setBorder(BorderFactory.createRaisedBevelBorder());
btnequal.setText("=");
btnequal.addActionListener(new CalculatorFrame_btnequal_actionAdapter(this));
this.getContentPane().setBackground(UIManager.getColor(
"MenuItem.background"));
this.setTitle("计算器");
this.getContentPane().add(txtresult);
this.getContentPane().add(btn1);
this.getContentPane().add(btn0);
this.getContentPane().add(btnclear);
this.getContentPane().add(btnplus);
this.getContentPane().add(btnequal);
this.getContentPane().add(btn2);
this.getContentPane().add(btn3);
this.getContentPane().add(btnminus);
this.getContentPane().add(btn4);
this.getContentPane().add(btn7);
this.getContentPane().add(btn5);
this.getContentPane().add(btn6);
this.getContentPane().add(btnjultiply);
this.getContentPane().add(btndivide);
this.getContentPane().add(btn9);
this.getContentPane().add(btn8);
}

public void btnplus_actionPerformed(ActionEvent e) {
action = "plus";
operand1 = txtresult.getText();
txtresult.setText("");
flag = true;
}

public void btnminus_actionPerformed(ActionEvent e) {
action = "minus";
operand1 = txtresult.getText();
txtresult.setText("");
flag = true;
}

public void btnjultiply_actionPerformed(ActionEvent e) {
action = "multiply";
operand1 = txtresult.getText();
txtresult.setText("");
flag = true;
}

public void btndivide_actionPerformed(ActionEvent e) {
action = "divide";
operand1 = txtresult.getText();
txtresult.setText("");
flag = true;
}

public void btnclear_actionPerformed(ActionEvent e) {
txtresult.setText("");
}

public void btn1_actionPerformed(ActionEvent e) {
if (flag) {
txtresult.setText(btn1.getActionCommand());
flag=false;
} else {
txtresult.setText(txtresult.getText() + btn1.getActionCommand());
}

}

public void btn2_actionPerformed(ActionEvent e) {
if (flag) {
txtresult.setText(btn2.getActionCommand());
flag=false;
} else {
txtresult.setText(txtresult.getText() + btn2.getActionCommand());
}

}

public void btn3_actionPerformed(ActionEvent e) {
if (flag) {
txtresult.setText(btn3.getActionCommand());
flag=false;
} else {
txtresult.setText(txtresult.getText() + btn3.getActionCommand());
}

}

public void btn4_actionPerformed(ActionEvent e) {
if (flag) {
txtresult.setText(btn4.getActionCommand());
flag=false;
} else {
txtresult.setText(txtresult.getText() + btn4.getActionCommand());
}

}

public void btn5_actionPerformed(ActionEvent e) {
if (flag) {
txtresult.setText(btn5.getActionCommand());
flag=false;
} else {
txtresult.setText(txtresult.getText() + btn5.getActionCommand());
}

}

public void btn6_actionPerformed(ActionEvent e) {
if (flag) {
txtresult.setText(btn6.getActionCommand());
flag=false;
} else {
txtresult.setText(txtresult.getText() + btn6.getActionCommand());
}

}

public void btn7_actionPerformed(ActionEvent e) {
if (flag) {
txtresult.setText(btn7.getActionCommand());
flag=false;
} else {
txtresult.setText(txtresult.getText() + btn7.getActionCommand());
}

}

public void btn8_actionPerformed(ActionEvent e) {
if (flag) {
txtresult.setText(btn8.getActionCommand());
flag=false;
} else {
txtresult.setText(txtresult.getText() + btn8.getActionCommand());
}

}

public void btn9_actionPerformed(ActionEvent e) {
if (flag) {
txtresult.setText(btn9.getActionCommand());
flag=false;
} else {
txtresult.setText(txtresult.getText() + btn9.getActionCommand());
}

}

public void btn0_actionPerformed(ActionEvent e) {
if (flag) {
txtresult.setText(btn0.getActionCommand());
flag=false;
} else {
txtresult.setText(txtresult.getText() + btn0.getActionCommand());
}

}

public void btnequal_actionPerformed(ActionEvent e) {
double digit1, digit2;
operand2 = txtresult.getText();
if (flag == false) {
if (action.equals("plus")) {
digit1 = Double.parseDouble(operand1);
digit2 = Double.parseDouble(operand2);
result = digit1 + digit2;
txtresult.setText(String.valueOf((int) result));
flag = true;
} else if (action.equals("minus")) {
digit1 = Double.parseDouble(operand1);
digit2 = Double.parseDouble(operand2);
result = digit1 - digit2;
txtresult.setText(String.valueOf((int) result));
flag = true;
} else if (action.equals("multiply")) {
digit1 = Double.parseDouble(operand1);
digit2 = Double.parseDouble(operand2);
result = digit1 * digit2;
txtresult.setText(String.valueOf((int) result));
flag = true;
} else if (action.equals("divide")) {
digit1 = Double.parseDouble(operand1);
digit2 = Double.parseDouble(operand2);
result = digit1 / digit2;
if (digit2==0) {
txtresult.setText("ERROR");
flag=true;
} else {
txtresult.setText(String.valueOf((int) result));
flag = true;
}
}

}

}

class CalculatorFrame_btnequal_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btnequal_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btnequal_actionPerformed(e);
}
}

class CalculatorFrame_btn0_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btn0_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btn0_actionPerformed(e);
}
}

class CalculatorFrame_btn9_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btn9_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btn9_actionPerformed(e);
}
}

class CalculatorFrame_btn8_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btn8_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btn8_actionPerformed(e);
}
}

class CalculatorFrame_btn7_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btn7_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btn7_actionPerformed(e);
}
}

class CalculatorFrame_btn6_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btn6_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btn6_actionPerformed(e);
}
}

class CalculatorFrame_btn5_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btn5_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btn5_actionPerformed(e);
}
}

class CalculatorFrame_btn4_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btn4_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btn4_actionPerformed(e);
}
}

class CalculatorFrame_btn2_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btn2_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btn2_actionPerformed(e);
}
}

class CalculatorFrame_btn3_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btn3_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btn3_actionPerformed(e);
}
}

class CalculatorFrame_btnclear_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btnclear_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btnclear_actionPerformed(e);
}
}

class CalculatorFrame_btndivide_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btndivide_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btndivide_actionPerformed(e);
}
}

class CalculatorFrame_btnjultiply_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btnjultiply_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btnjultiply_actionPerformed(e);
}
}

class CalculatorFrame_btnminus_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btnminus_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btnminus_actionPerformed(e);
}
}

class CalculatorFrame_btnplus_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btnplus_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btnplus_actionPerformed(e);
}
}

class CalculatorFrame_btn1_actionAdapter implements ActionListener {
private CalculatorFrame adaptee;
CalculatorFrame_btn1_actionAdapter(CalculatorFrame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.btn1_actionPerformed(e);
}
}
}

public class Calculator {

public static void main(String[] args) {

CalculatorFrame Objcal=new CalculatorFrame();

Objcal.setSize(410,320);
Objcal.setVisible(true);
}
}

热点内容
循迹小车算法 发布:2024-12-22 22:28:41 浏览:82
scss一次编译一直生成随机数 发布:2024-12-22 22:04:24 浏览:956
嫁接睫毛加密 发布:2024-12-22 21:50:12 浏览:975
linuxbin文件的安装 发布:2024-12-22 21:46:07 浏览:798
vlcforandroid下载 发布:2024-12-22 21:45:26 浏览:664
电脑做网关把数据发送至服务器 发布:2024-12-22 21:44:50 浏览:432
新华三代理什么牌子的服务器 发布:2024-12-22 21:33:21 浏览:342
欢太会员密码是什么 发布:2024-12-22 20:57:28 浏览:74
sqllocaldb 发布:2024-12-22 20:07:08 浏览:126
如何找到我的服务器 发布:2024-12-22 19:52:14 浏览:301