1.?手机算器手机算器ֻ???ܼ?????Դ??
2.用c语言程序设计一个简单计算器,求其源代码
3.用JAVA编写的科学计算器源代码
4.java 写的计算器源代码只实现加减乘除四则运算即可
?ֻ???ܼ?????Դ??
import java.awt.*;
import java.awt.event.*;
public class Calculator extends WindowAdapter implements ActionListener
{
private double result=0,data1=0,radixPointDepth=1;
private boolean radixPointIndicate=false,resultIndicate=false;
private char prec='+';
private Frame f;
private TextField tf;
private Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b,b,b,b,b,b,b,b;
private Panel p;
static public void main(String args[])
{
Calculator de=new Calculator();
de.go();
}
public void go()
{
f=new Frame("计算器");
p=new Panel();
p.setLayout(new GridLayout(4,4));
tf=new TextField();
b1=new Button("7");
b2=new Button("8");
b3=new Button("9");
b4=new Button("+");
b5=new Button("4");
b6=new Button("5");
b7=new Button("6");
b8=new Button("-");
b9=new Button("1");
b=new Button("2");
b=new Button("3");
b=new Button("*");
b=new Button("0");
b=new Button(".");
b=new Button("=");
b=new Button("/");
b=new Button("清零");
f.add(tf,"North");
f.add(p,"Center");
f.add(b,"South");
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(b);
p.add(b);
p.add(b);
p.add(b);
p.add(b);
p.add(b);
p.add(b);
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);
b.addActionListener(this);
b.addActionListener(this);
b.addActionListener(this);
b.addActionListener(this);
b.addActionListener(this);
b.addActionListener(this);
b.addActionListener(this);
b.addActionListener(this);
f.addWindowListener(this);
f.setSize(,);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String s;
s=e.getActionCommand();
switch(s.charAt(0))
{
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
if(resultIndicate)
{
result=0;
data1=0;
prec='+';
}
Integer Int1=new Integer(s);
if(radixPointIndicate)
{
radixPointDepth=radixPointDepth/;
data1=data1+(Int1.intValue())*radixPointDepth;
}
else
{
data1=data1*+(Int1.intValue());
}
Double displayNumber=new Double(data1);
tf.setText(displayNumber.toString());
resultIndicate=false;
break;
case '+': case '-':case '*':case '/':case '=':
if(s.charAt(0)!='='&&resultIndicate)
{
prec=s.charAt(0);
resultIndicate=false;
}
else
{
switch(prec)
{
case '+':
result=result+data1;
break;
case '-':
result=result-data1;
break;
case '*':
result=result*data1;
break;
case '/':
result=result/data1;
break;
}
}
radixPointIndicate=false;
radixPointDepth=1;
displayNumber=new Double(result);
tf.setText(displayNumber.toString());
if(s.charAt(0)!='=')
{
data1=0;
prec=s.charAt(0);
}
else
{
resultIndicate=true;
}
break;
case '.':
radixPointIndicate=true;
break;
}
if(s.equals("清零"))
{
result=0;
data1=0;
radixPointDepth=1;
tf.setText("");
}
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
用c语言程序设计一个简单计算器,求其源代码
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* Define constants for the calculator */
#define UP 0x
#define DOWN 0x
#define LEFT 0x4B
#define RIGHT 0x4D
#define ENTER 0x0D
/* Global variables */
double num1 = 0, num2 = 0, result = 0;
char str1[] = ".+-*/知消扒Qc=^%";
char cnum[5], str2[] = "", c;
int x, y, x0, y0, i, j, v, m, n, act, flag = 1;
/* Function prototypes */
void drawboder(void);
void initialize(void);
void computer(void);
void changetextstyle(int font, int direction, int charsize);
void mwindow(char *header);
int specialkey(void);
int arrow();
/* Main function */
int main() {
initialize();
computer();
closegraph();
return 0;
}
/* Initialize the graphics system */
void initialize(void) {
int xasp, yasp;
GraphDriver = DETECT;
initgraph( &GraphDriver, &GraphMode, "" );
ErrorCode = graphresult();
if (ErrorCode != grOk) {
printf("Graphics System Error: %s\n", grapherrormsg(ErrorCode));
exit(1);
}
getpalette( &palette );
MaxColors = getmaxcolor() + 1;
MaxX = getmaxx();
MaxY = getmaxy();
getaspectratio( &xasp, &yasp );
AspectRatio = (double)xasp / (double)yasp;
}
/* Main calculator function */
void computer(void) {
struct viewporttype vp;
int color, height, width;
mwindow("Calculator");
color = 7;
getviewsettings( &vp );
width = (vp.right + 1) / ;
height = (vp.bottom - ) / ;
x = width / 2;
y = height / 2;
setfillstyle(SOLID_FILL, color + 3);
bar( x + width * 2, y, x + 7 * width, y + height );
setcolor( color + 3 );
rectangle( x + width * 2, y, x + 7 * width, y + height );
setcolor(RED);
outtextxy(x + 3 * width, y + height / 2, "0.");
x = 2 * width - width / 2;
y = 2 * height + height / 2;
for (j = 0; j < 4; ++j) {
for (i = 0; i < 5; ++i) {
setfillstyle(SOLID_FILL, color);
setcolor(RED);
bar( x, y, x + width, y + height );
rectangle( x, y, x + width, y + height );
sprintf(str2, "%c", str1[j * 5 + i]);
outtextxy( x + (width / 2), y + height / 2, str2);
x += width + (width / 2);
}
y += (height / 2) * 3;
x = 2 * width - width / 2;
}
x0 = 2 * width;
y0 = 3 * height;
x = x0;
y = y0;
gotoxy(x, y);
arrow();
m = 0;
n = 0;
strcpy(str2, "");
while ((v = specialkey()) != ) {
while ((v = specialkey()) != ENTER) {
putimage(x, y, rar, XOR_PUT);
if (v == RIGHT) {
if (x >= x0 + 6 * width)
x = x0;
else
x += width + width / 2;
m++;
}
if (v == LEFT) {
if (x <= x0)
x = x0 + 6 * width;
else
x -= width - width / 2;
m--;
}
if (v == UP) {
if (y <= y0)
y = y0 + 4 * height + height / 2;
else
y -= height - height / 2;
n--;
}
if (v == DOWN) {
if (y >= 7 * height)
y = y0;
else
y += height + height / 2;
n++;
}
putimage(x, y, rar, XOR_PUT);
}
c = str1[n * 5 + m];
if (isdigit(c) || c == '.') {
if (flag == -1) {
strcpy(str2, "-");
flag = 1;
}
sprintf(temp, "%c", c);
strcat(str2, temp);
setfillstyle(SOLID_FILL, color + 3);
bar(2 * width + width / 2, height / 2, * width / 2, 3 * height / 2);
outtextxy(5 * width, height, str2);
}
if (c == '+') {
num1 = atof(str2);
strcpy(str2, "");
act = 1;
setfillstyle(SOLID_FILL, color + 3);
bar(2 * width + width / 2, height / 2, * width / 2, 3 * height / 2);
outtextxy(5 * width, height, "0.");
}
if (c == '-') {
if (strcmp(str2, "") == 0)
flag = -1;
else {
num1 = atof(str2);
strcpy(str2, "");
act = 2;
setfillstyle(SOLID_FILL, color + 3);
bar(2 * width + width / 2, height / 2, * width / 2, 3 * height / 2);
outtextxy(5 * width, height, "0.");
}
}
if (c == '*') {
num1 = atof(str2);
strcpy(str2, "");
act = 3;
setfillstyle(SOLID_FILL, color + 3);
bar(2 * width + width / 2, height / 2, * width / 2, 3 * height / 2);
outtextxy(5 * width, height, "0.");
}
if (c == '/') {
num1 = atof(str2);
strcpy(str2, "");
act = 4;
setfillstyle(SOLID_FILL, color + 3);
bar(2 * width + width / 2, height / 2, * width / 2, 3 * height / 2);
outtextxy(5 * width, height, "0.");
}
if (c == '^') {
num1 = atof(str2);
strcpy(str2, "");
act = 5;
setfillstyle(SOLID_FILL, color + 3);
bar(2 * width + width / 2, height / 2, * width / 2, 3 * height / 2);
outtextxy(5 * width, height, "0.");
用JAVA编写的科学计算器源代码
这个你参考一下。
import javax.swing.*;
//import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
//计算器显示结果的多功多功窗体
class Result extends JPanel
{
JTextField text = new JTextField("0"); //text先是输入和结果
Result()
{
text.setHorizontalAlignment(SwingConstants.RIGHT); //讲输入的数字或得到的结果在text的右边显示
text.setEnabled(false); //文本框不能编辑
setLayout(new BorderLayout()); //设定布局管理器边框布局
add(text, BorderLayout.CENTER); //text放置在窗体的中间
}
}
//计算器数字按钮定义面板
class Number_Key extends JPanel
{
JButton zero = new JButton("0");//数字键0
JButton one = new JButton("1");//数字键1
JButton two = new JButton("2");//数字键2
JButton three = new JButton("3");//数字键3
JButton four = new JButton("4");//数字键4
JButton five = new JButton("5");//数字键5
JButton six = new JButton("6");//数字键6
JButton seven = new JButton("7");//数字键7
JButton eight = new JButton("8");//数字键8
JButton nine = new JButton("9");//数字键9
JButton plus = new JButton("+");
JButton sub = new JButton("-");
JButton mul = new JButton("*");
JButton div = new JButton("/");
JButton equal = new JButton("=");
JButton ce = new JButton("ce");//置零键
JButton point = new JButton(".");
JButton tzero = new JButton("");
Number_Key()
{
setLayout(new GridLayout(6, 3, , ));//定义布局管理器为网格布局
//添加各个按钮键
add(seven);
add(eight);
add(nine);
add(four);
add(five);
add(six);
add(one);
add(two);
add(three);
add(zero);
add(tzero);
add(plus);
add(sub);
add(mul);
add(div);
add(point);
add(equal);
add(ce);
}
}
//计算器主类
class sakura extends JFrame implements ActionListener
{
Result result = new Result();//定义text的面板
Number_Key number_key = new Number_Key();//定义按钮面板
//当点击按钮+、-、计能计*、源码源码2048 github 源码/时,手机算器手机算器com = true
boolean com = false;
//当i=0时说明是多功多功食堂消费系统 源码我们第一次输入,字符串sum不会累加
int i = 0;
//存放text的计能计内容
String sum = "";
//存放点击按钮+、-、源码源码*、手机算器手机算器/之前的多功多功数值
double total = 0;
//+、-、计能计*、源码源码/的手机算器手机算器彩票源码博客代号分别为1,2,多功多功3,计能计4
int symbol = 0;
sakura()
{
super("Calculator");//设定标题
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设定关闭窗体时退出程序
JPanel pane = new JPanel();//定义主面板
pane.setLayout(new BorderLayout());
pane.add(result,币交易源码php BorderLayout.NORTH);
pane.add(number_key, BorderLayout.SOUTH);
number_key.one.addActionListener(this);//对1按钮添加监听事件
number_key.two.addActionListener(this);//对2按钮添加监听事件
number_key.three.addActionListener(this);//对3按钮添加监听事件
number_key.four.addActionListener(this);//对4按钮添加监听事件
number_key.five.addActionListener(this);//对5按钮添加监听事件
number_key.six.addActionListener(this);//对6按钮添加监听事件
number_key.seven.addActionListener(this);//对7按钮添加监听事件
number_key.eight.addActionListener(this);//对8按钮添加监听事件
number_key.nine.addActionListener(this);//对9按钮添加监听事件
number_key.zero.addActionListener(this);//对0按钮添加监听事件
number_key.ce.addActionListener(this);//对置零按钮添加监听事件
number_key.plus.addActionListener(this);//对+按钮添加监听事件
number_key.equal.addActionListener(this);//对=按钮添加监听事件
number_key.sub.addActionListener(this);//对-按钮添加监听事件
number_key.mul.addActionListener(this);//对*按钮添加监听事件
number_key.div.addActionListener(this);//对/按钮添加监听事件
number_key.tzero.addActionListener(this);//对按钮添加监听事件
number_key.point.addActionListener(this);//对.按钮添加监听事件
setContentPane(pane);
pack();//初始化窗体大小为正好盛放所有按钮
}
//各个按钮触发的事件
public void actionPerformed(ActionEvent e) {
/*如果是点击数字按钮那么先要判断是否在此之前点击了+、-、*、/、php简单源码例子=,如果是那么com=true
* 如果没有com= false;或者是否点击数字键,如果是i = 1,如果没有 i = 0;
**/
if (e.getSource() == number_key.one)
{
if (com || i == 0)
{
result.text.setText("1");
com = false;
i = 1;
}
else
{
sum = result.text.getText();
result.text.setText(sum + "1");
}
}
else if (e.getSource() == number_key.two)
{
if (com || i == 0)
{
result.text.setText("2");
com = false;
i = 1;
}
else
{
sum = result.text.getText();
result.text.setText(sum + "2");
}
}
else if (e.getSource() == number_key.three)
{
if (com || i == 0)
{
result.text.setText("3");
com = false;
i = 1;
}
else
{
sum = result.text.getText();
result.text.setText(sum + "3");
}
}
else if (e.getSource() == number_key.four)
{
if (com || i == 0)
{
result.text.setText("4");
com = false;
i = 1;
}
else
{
sum = result.text.getText();
result.text.setText(sum + "4");
}
}
else if (e.getSource() == number_key.five)
{
if (com || i == 0)
{
result.text.setText("5");
com = false;
i = 1;
}
else
{
sum = result.text.getText();
result.text.setText(sum + "5");
}
}
else if (e.getSource() == number_key.six)
{
if (com || i == 0)
{
result.text.setText("6");
com = false;
i = 1;
}
else
{
sum = result.text.getText();
result.text.setText(sum + "6");
}
}
else if (e.getSource() == number_key.seven)
{
if (com || i == 0)
{
result.text.setText("7");
com = false;
i = 1;
}
else
{
sum = result.text.getText();
result.text.setText(sum + "7");
}
}
else if (e.getSource() == number_key.eight)
{
if (com || i == 0)
{
result.text.setText("8");
com = false;
i = 1;
}
else
{
sum = result.text.getText();
result.text.setText(sum + "8");
}
}
else if (e.getSource() == number_key.nine)
{
if (com || i == 0)
{
result.text.setText("9");
com = false;
i = 1;
}
else
{
sum = result.text.getText();
result.text.setText(sum + "9");
}
}
/*对于0这个按钮有一定的说法,在我的程序里不会出现如这样的情况,我加了判断条件就是
* 如果text中的数值=0就要判断在这个数值中是否有.存在?如果有那么就在原来数值基础之上添
* 加0;否则保持原来的数值不变
*/
else if (e.getSource() == number_key.zero)
{
if (com || i == 0)
{
result.text.setText("0");
com = false;
i = 1;
}
else
{
sum = result.text.getText();
if (Float.parseFloat(sum) > 0 || Float.parseFloat(sum) < 0)
{
result.text.setText(sum + "0");
}
else
{
if (sum.trim().indexOf(".") == -1)
{
result.text.setText(sum);
}
else
{
result.text.setText(sum + "0");
}
}
}
}
else if (e.getSource() == number_key.ce)
{
result.text.setText("0");
i = 0;
com = true;
}
else if (e.getSource() == number_key.tzero)
{
if (com || i == 0)
{
result.text.setText("0");
com = false;
i = 1;
}
else
{
sum = result.text.getText();
if (Float.parseFloat(sum) > 0 || Float.parseFloat(sum) < 0)
{
result.text.setText(sum + "");
}
else
{
if (sum.trim().indexOf(".") == -1)
{
result.text.setText(sum);
}
else
{
result.text.setText(sum + "");
}
}
}
}
/*本程序不会让一个数值中出现2个以上的小数点.具体做法是:判断是否已经存在.存在就不添加,
* 不存在就添加.
*/
else if (e.getSource() == number_key.point)
{
if (com || i == 0)
{
result.text.setText("0.");
com = false;
i = 1;
}
else
{
sum = result.text.getText();
if (sum.trim().indexOf(".") == -1)
{
result.text.setText(sum + ".");
}
else
{
result.text.setText(sum);
}
}
}
//获得点击+之前的数值
else if (e.getSource() == number_key.plus)
{
com = true;
i = 0;
total = Double.parseDouble(result.text.getText());
symbol = 1;
}//获得点击-之前的数值
else if (e.getSource() == number_key.sub)
{
com = true;
i = 0;
total = Double.parseDouble(result.text.getText());
symbol = 2;
}//获得点击*之前的数值
else if (e.getSource() == number_key.mul)
{
com = true;
i = 0;
total = Double.parseDouble(result.text.getText());
System.out.println(total);
symbol = 3;
}//获得点击/之前的数值
else if (e.getSource() == number_key.div)
{
com = true;
i = 0;
total = Double.parseDouble(result.text.getText());
symbol = 4;
}
else if (e.getSource() == number_key.equal)
{
switch (symbol)
{
case 1 ://计算加法
{
double ad =
total + Double.parseDouble(result.text.getText());
result.text.setText(ad + "");
i = 0;
sum = "";
break;
}
case 2 ://计算减法
{
double ad =
total - Double.parseDouble(result.text.getText());
result.text.setText(String.valueOf(ad));
i = 0;
sum = "";
break;
}
case 3 ://计算乘法
{
double ad =
total * Double.parseDouble(result.text.getText());
result.text.setText(ad + "");
i = 0;
sum = "";
break;
}
case 4 ://计算除法
{
double ad =
total / Double.parseDouble(result.text.getText());
result.text.setText(ad + "");
i = 0;
sum = "";
break;
}
}
System.out.println(com);
}
}
public static void main(String[] args)
{
sakura ww = new sakura();
ww.setVisible(true) ;
}
}
java 写的计算器源代码只实现加减乘除四则运算即可
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Vector;
public class calculator
{
String str1="0"; //运算数1 初值一定为0 为了程序的安全
String str2="0"; //运算数2
String fh="+"; //运算符
String jg="";//结果
//状态开关 重要
int k1=1;//开关1 用于选择输入方向 将要写入str2或 str2
int k2=1;//开关2 符号键 次数 k2>1说明进行的是2+3-9+8 这样的多符号运算
int k3=1;//开关3 str1 是否可以被清0 ==1时可以 !=1时不能被清0
int k4=1;//开关4 str2 同上
int k5=1;//开关5 控制小数点可否被录入 ==1时可以 !=1 输入的小数点被丢掉
JButton jicunqi; //寄存器 记录 是否连续按下符号键
Vector vt=new Vector(,);
JFrame frame=new JFrame("sunshine---计算器");
JTextField jg_TextField=new JTextField(jg,);//列
JButton clear_Button=new JButton("清除");
JButton button0=new JButton("0");
JButton button1=new JButton("1");
JButton button2=new JButton("2");
JButton button3=new JButton("3");
JButton button4=new JButton("4");
JButton button5=new JButton("5");
JButton button6=new JButton("6");
JButton button7=new JButton("7");
JButton button8=new JButton("8");
JButton button9=new JButton("9");
JButton button_Dian=new JButton(".");
JButton button_jia=new JButton("+");
JButton button_jian=new JButton("-");
JButton button_cheng=new JButton("*");
JButton button_chu=new JButton("/");
JButton button_dy=new JButton("=");
public static void main(String[] args)
{
calculator calculator=new calculator();
}
calculator()
{
jg_TextField.setHorizontalAlignment(JTextField.RIGHT );//文本框 右对齐
JPanel pan=new JPanel();
pan.setLayout(new GridLayout(4,4,5,5));//四行四列 边距为5像素
pan.add(button7);
pan.add(button8);
pan.add(button9);
pan.add(button_chu);
pan.add(button4);
pan.add(button5);
pan.add(button6);
pan.add(button_cheng);
pan.add(button1);
pan.add(button2);
pan.add(button3);
pan.add(button_jian);
pan.add(button0);
pan.add(button_Dian);
pan.add(button_dy);
pan.add(button_jia);
pan.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));//pan对象的边距
JPanel pan2=new JPanel();
pan2.add(jg_TextField);
JPanel pan3=new JPanel(); //为什么要 多此一句呢? 因为我不会设置 按钮的大小
pan3.setLayout(new FlowLayout());
pan3.add(clear_Button);
//clear_Button.setSize(,);//设置清零按钮的大小 吗的 不好使 !!
frame.setLocation(, ); //主窗口 出现在位置
frame.setResizable(false); //不能调大小
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(pan2,BorderLayout.NORTH);
frame.getContentPane().add(pan,BorderLayout.CENTER);
frame.getContentPane().add(pan3,BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
//以上是 控件 和 布局
//下面是事件处理 程 序
//--------------- 数 字 键 ----------------
class JianTing implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String ss=((JButton)e.getSource()).getText();
jicunqi=(JButton)e.getSource();
vt.add(jicunqi);
if (k1==1)
{
if(k3==1)
{
str1="";
k5=1;//还原开关k5状态
}
str1=str1+ss;
//k2=1;
k3=k3+1;
//System.out.println(str1);
jg_TextField.setText(str1);//显示
}
else if(k1==2)
{
if (k4==1)
{
str2="";
k5=1; //还原开关k5状态
}
str2=str2+ss;
//k2=2;
k4=k4+1;
///////////////测试////////////////
jg_TextField.setText(str2);
}
}
}
//--------符 号-----------
class JianTing_fh implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String ss2=((JButton)e.getSource()).getText();
jicunqi=(JButton)e.getSource();
vt.add(jicunqi);
if(k2==1)
{
k1=2;//开关 k1 为1时,向数1写 为2时,向数2写
k5=1;
fh=ss2;
k2=k2+1;//按符号键的次数
}
else
{
int a=vt.size();
JButton c=(JButton)vt.get(a-2); if(!(c.getText().equals("+"))&&!(c.getText().equals("-"))&&!(c.getText().equals("*"))&&!(c.getText().equals("/")))
{
yuns();
str1=jg;
k1=2;//开关 k1 为1时,向数1写 为2时,向数2写
k5=1;
k4=1;
fh=ss2;
} k2=k2+1;
}
}
}
//--------清除-------
class JianTing_clear implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jicunqi=(JButton)e.getSource();
vt.add(jicunqi);
k5=1;
k2=1;
k1=1;
k3=1;
k4=1;
str1="0";
str2="0";
fh="";
jg="";
jg_TextField.setText(jg);
vt.clear();
}
}
//----------------等 于 ---------------------
class JianTing_dy implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jicunqi=(JButton)e.getSource();
vt.add(jicunqi);
yuns();
k1=1; //还原开关k1状态
//str1=jg;
k2=1;
k3=1;//还原开关k3状态
k4=1; //还原开关k4状态
str1=jg; //为7+5= +5= 这种计算做准备
}
}
//----------------小数点 ---------------------
class JianTing_xiaos implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jicunqi=(JButton)e.getSource();
vt.add(jicunqi);
if(k5==1)
{
String ss2=((JButton)e.getSource()).getText();
if (k1==1)
{
if(k3==1)
{
str1="";
k5=1; //还原开关k5状态
}
str1=str1+ss2;
//k2=1;
k3=k3+1;
//System.out.println(str1);
jg_TextField.setText(str1);//显示
}
else if(k1==2)
{
if (k4==1)
{
str2="";
k5=1; //还原开关k5状态
}
str2=str2+ss2;
//k2=2;
k4=k4+1;
///////////////测试////////////////
jg_TextField.setText(str2);
}
}
k5=k5+1;
}
}
//注册 监听器
JianTing_dy jt_dy=new JianTing_dy();
JianTing jt= new JianTing();//临听数字键
JianTing_fh jt_fh= new JianTing_fh();//临 听符 号键
JianTing_clear jt_c=new JianTing_clear(); //清除键
JianTing_xiaos jt_xs=new JianTing_xiaos();// 小数点 键
button7.addActionListener(jt);
button8.addActionListener(jt);
button9.addActionListener(jt);
button_chu.addActionListener(jt_fh);
button4.addActionListener(jt);
button5.addActionListener(jt);
button6.addActionListener(jt);
button_cheng.addActionListener(jt_fh);
button1.addActionListener(jt);
button2.addActionListener(jt);
button3.addActionListener(jt);
button_jian.addActionListener(jt_fh);
button0.addActionListener(jt);
button_Dian.addActionListener(jt_xs);
button_dy.addActionListener(jt_dy);
button_jia.addActionListener(jt_fh);
clear_Button.addActionListener(jt_c);
//关闭事件处理程序
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
//---------------计 算------------------
public void yuns()
{
double a2,b2;//运算数1,2
String c=fh;// 运算符
double jg2=0 ;//结果
if (c.equals(""))
{
//System.out.println("请输入运算符");
jg_TextField.setText("请输入运算符");
}
else
{
System.out.println("str1:"+str1);//调试时 使 用
System.out.println("str2:"+str2);//调试时 使 用
System.out.println("运算符:"+fh);//调试时 使 用
if (str1.equals(".")) //字符串 "." 转换成double型数据时 会出错 所以手工转
str1="0.0";
if (str2.equals("."))
str2="0.0";
a2=Double.valueOf(str1).doubleValue();
b2=Double.valueOf(str2).doubleValue();
System.out.println("double型的a2:"+a2); //调试时 使 用
System.out.println("double型的b2:"+b2); //调试时 使 用
if (c.equals("+"))
{
jg2=a2+b2;
}
if (c.equals("-"))
{
jg2=a2-b2;
}
if (c.equals("*"))
{
jg2=a2*b2;
}
if (c.equals("/"))
{
if(b2==0)
{
jg2=0;// by 0 cu!
}
else
{
jg2=a2/b2;
}
}
System.out.println("double型a2"+fh+"b2结果:"+jg2);
System.out.println();
jg=((new Double(jg2)).toString());
jg_TextField.setText(jg);
}
}
}
「尊重」徐巧芯合體柯文哲 費鴻泰:相信自己會獲勝
他们的身体和心灵,是互联网的垃圾过滤器
稱長者打疫苗熱暈為假訊息 盧秀燕改口道歉了
《可憐的東西》奪奧斯卡最佳美術、造型和最佳服裝設計獎
交友网站H5源码_交友网站h5源码是什么
傳電價4年多來首漲 用電大戶、豪宅估漲8%