用JAVA编写的傻瓜计算器
作用:
1.可以实现加法、减法、乘法、除法简单运算且是单一运算,不可混合使用。
2.CE为清除键
3.没有小数点O(∩_∩)O
思路:
创建JFrame窗口,设置标题,创建JButton,创建文本框JTextField用作显示。
先定义各种按钮类型,用作成员。定义窗口方法对窗口进行设置。定义按钮事件方法,每个按钮的
每次点下在文本框都会进行打印。以运算符为界限对字符串进行分割,并把分割后的字符串放入新
建的数组当中。对字符串数组内容访问转换为整数类型,进行运算。运算的结果为double类型的并
把结果打印到文本框中。
成品:
代码实现:
package test1;
import javax.print.attribute.standard.JobMessageFromOperator;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
public class Window extends JFrame{
private JButton ADD=new JButton("+");
private JButton SUB=new JButton("-");
private JButton SUM=new JButton("x");
private JButton DIV=new JButton("/");
private JButton l=new JButton("0");
private JButton y=new JButton("1");
private JButton e=new JButton("2");
private JButton s=new JButton("3");
private JButton s4=new JButton("4");
private JButton w=new JButton("5");
private JButton l6=new JButton("6");
private JButton q=new JButton("7");
private JButton b=new JButton("8");
private JButton j=new JButton("9");
private JButton dengyu=new JButton("=");
private JButton qingchu=new JButton("CE");
private JTextField jt=new JTextField();
private String shuju;
public Window(){
window();
addJb();
addjt();
add();
this.setVisible(true);
}
public void window(){
//窗体大小
this.setSize(570,550);
//窗体