计算器
截图
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;
public class Calulator extends JFrame implements ActionListener {
private static final long serialVersionUID = 12345678L;
private final String[] NBKEYS = { "7", "8", "9", "/", "sqrt", "4", "5", "6",
"*", "%", "1", "2", "3", "-", "1/x", "0", "+/-", ".", "+", "=" };
private final String[] MK = { " ", "MC", "MR", "MS", "M+" };
private final String[] CMKEYS = { "Backspace", "CHCEK", "AGAIN" };
/**计算器上键的按钮 */
private JButton keys[] = new JButton[NBKEYS.length];
/** 计算器上的功能键的按钮 */
private JButton cmkeys[] = new JButton[CMKEYS.length];
/** 计算器左边的 M 的按钮 */
private JButton mk[] = new JButton[MK.length];
/** 计算结果文本框 */
private JTextField resultText = new JTextField("0");
/**标志用户按的是否是整个表达式的第一个数字,或者是运算符后的第一个数字 */
private boolean firstDigit = true;
评论0
最新资源