});
three.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(s1.equals("0")) s1="3";
else {text.setText(s1+"3");
s1+="3";}
text.setText(s1);
}
});
zero.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(!s1.equals("0")) s1+="0";
text.setText(s1);
}
});
but.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(c1=='0') {d1=Double.parseDouble(s1);if(d1!=0){c1 = '/';}}
else {d2=Double.parseDouble(s1);
judgec1(text);
c1 = '/';}
s1="0";
}
});
substract.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(c1=='0') {d1=Double.parseDouble(s1);if(d1!=0){c1 = '-';}}
else {d2=Double.parseDouble(s1);
judgec1(text);
c1 = '-';}
s1="0";
}
});
ride.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(c1=='0') {d1=Double.parseDouble(s1);if(d1!=0){c1 = '*';}}
else {d2=Double.parseDouble(s1);
judgec1(text);
c1 = '*';}
s1="0";
}
});
add.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(c1=='0') {d1=Double.parseDouble(s1);if(d1!=0){c1 = '+';}}
else {d2=Double.parseDouble(s1);
judgec1(text);
c1 = '+';}
s1="0";
}
});
/* Backspace.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(s1.length()!=0){
if(c1=='0') {text.setText(s1.substring(0, s1.length()-1));s1=s1.substring(0, s1.length()-1);}
else if (c1!='0'!s2.equals("0")) {text.setText(s2.substring(0, s1.length()-1));s2=s2.substring(0, s2.length()-1);}
}}
});*/
equal.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(c1=='0') d1=Double.parseDouble(s1);
else {d2=Double.parseDouble(s1);
judgec1(text);}
s1="0";
c1='0';
}
});
cclt.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
((Frame) e.getComponent()).dispose();
}
});
cclt.setResizable(false);
cclt.setVisible(true);
}
}
我们老师写的哦
求一个 JAVA 的 科学计算器 的 源代码我给你一个功能强大的计算器!已运行通过!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Calculator3 extends JFrame implements ActionListener {
private boolean dotExist, operated, equaled; // 帮助运算的布尔变量
private double storedNumber; // 目前的结果
private char lastOperator; // 表示上一运算符
private JTextField operation; // 结果栏
private JButton dot, plus, minus, multi, div, sqrt, equal, changePN, clear; // 运算符
private JButton[] numbers; // 数字
// 构造者
public Calculator3() {
setTitle("Calculator");
// 初始化变量
dotExist = false; // 表示当前的数是否有小数点
operated = false; // 表示任意运算符是否被按下
equaled = false; // 表示等号是否被按下
storedNumber = 0;
lastOperator = '?';
// 初始化窗口变量
operation = new JTextField("0");
operation.setEditable(false);
numbers = new JButton[10];
for (int i = 0; i10; i++)
numbers[i] = new JButton("" + i);
dot = new JButton(".");
plus = new JButton("+");
minus = new JButton("-");
multi = new JButton("*");
div = new JButton("/");
sqrt = new JButton("√");
equal = new JButton("=");
changePN = new JButton("±");
推荐阅读
- 生存经营题材电脑游戏下载,生存经营玩法的策略游戏
- 关于网际飞车游戏手机安卓版的信息
- 玩游戏算休闲娱乐吗,打游戏是不是娱乐
- 电脑显示器hdmi怎么连接电脑,显示器hdmi接口怎么连接电脑主机
- php操作数据库常用命令 php中数据库怎么设计
- html页面无法返回代码,html页面无法返回代码怎么办
- 查看端口sqlserver端口号,sql server查看端口号
- 硬盘异常关机怎么修复,硬盘出现故障会怎么样
- 服务器java代码 java编写服务器端