用JAVA编写计算器,要有+,-,*,/,CE,BackSpace键

来源:百度知道 编辑:UC知道 时间:2024/06/10 02:15:19
用JAVA编写计算器,只需要有+,-,*,/,=,CE,BackSpace功能

package com.xuzs.test;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Calculator extends JFrame implements ActionListener {

private static final long serialVersionUID = 1L;
private JTextField txtResult;
private JButton btnZero, btnOne, btnTwo, btnThree, btnFour, btnFive,
btnSix, btnSeven, btnEight, btnNine, btnPlus, btnMinus, btnTimes,
btnDivided, btnEqual, btnPoint, btnC, btnCE, btnSqrt, btnPlusMinus;
int z;
double x, y;
StringBuffer str;

public Calculator() {
super("计算器");
this.setSize(311, 231);
this.setLocation(300, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setLayout(new GridLayout(1, 1));// 网格布局
JPanel panel = new JPanel(new GridLayout(6, 1));// 面板 网格布局6行1列
this.add(panel);

txtResult = new JTextField("0");
Color BackColor = new Color(255, 2