程序功能简介:从最基本的加、减、乘、除,到基本数学函数处理,再到数的进制转换处理。
代码如下
/*文件名:Calculator.java
*说明:简易科学计算器
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends Frame implements ActionListener, WindowListener
{
private Container container;
private GridBagLayout layout;
private GridBagConstraints constraints;
private JTextField displayField; //计算结果显示区
private String lastCommand; //保存+,-,*,/,=命令0
private double result; //保存计算结果
private boolean start; //判断是否为数字的开始
private JMenuBar menubar;
private JMenuItem m_exit,m2_ejz,m2_bjz;
private Dialog dialog;
private Label label_dialog;
private JButton
button_sqrt,button_plusminus,button_CE,button_cancel,button_1,button_2,
button_3,button_4,button_5,button_6,button_7,button_8,button_9,button_0,
button_plus,button_minus,button_multiply,button_divide,button_point,
button_equal,button_log,button_tan,button_cos,button_sin,button_exp
;
public Calculator() //构造方法设置布局、为按钮注册事件监听器
{
super("Calculator");
this.setLocation(240,200);
this.setSize(350,300);
this.setResizable(true);
this.setLayout(new GridLayout(7,1));
this.addmyMenu(); //调用成员方法添加菜单
displayField=new JTextField(30);
this.add(displayField);
displayField.setEditable(true);
start=true;
result=0;
lastCommand = "=";
JPanel panel0=new JPanel();
panel0.setLayout(new GridLayout(1,4,4,4));
评论1
最新资源