package computer;//新建的一个名为computer的包
//引入需要用的Java包 如果要使swing组件正常运行,必须引入如下两个包
import java.awt.event.*;
import javax.swing.*; //为了使界面美观,我们为显示的区域加上了边框,所以引入以下包
import javax.swing.border.LineBorder;
/**
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* Builder, which is free for non-commercial use. If Jigloo is being used
* commercially (ie, by a corporation, company or business for any purpose
* whatever) then you should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details. Use of Jigloo implies
* acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
* PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
* ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
// 新建一个类 名字为computter1
public class computter1 extends JFrame implements ActionListener {
// implements ActionListener 集成 发生操作时调用
// 下面定义的是要用的组件和变量
private JMenuItem helpMenuItem;
private JMenu jMenu5;
private JButton jb7;
private JButton jb6;
private JButton jb5;
private JButton jb4;
private JButton jb3;
private JButton jb2;
private JButton jb1;
private JLabel display;
private JMenuItem del;
// private JSeparator jSeparator1;
// private JMenuItem pasteMenuItem;
// private JMenuItem copyMenuItem;
// private JMenuItem cutMenuItem;
private JMenu exit;
private JButton jb20;
private JButton jb19;
private JButton jb18;
private JButton jb17;
private JButton jb16;
private JButton jb15;
private JButton jb14;
private JButton jb13;
private JButton jb12;
private JButton jb11;
private JButton jb10;
private JButton jb9;
private JButton jb8;
private JMenuItem zt;
private JMenuItem copy;
private JMenu bj;
private JMenuBar jMenuBar1;
private int a ;
//value1 和value2分别存储两个操作数例如:vvalue1+vlaue2
private String b,value1="off",value2="off",value3="off";
private double sqr[],jb[],v=0,v1=0,sq,sq1;
private int m;// 取出显示的字符串的长度
private int ii;//判断是否有小数点,如果ii=0就没有,ii=1就有小数点
private int add,reduce,mult,division;//分别表示+-*/四则运算
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
computter1 inst = new computter1();// 实例化 computter1()类
inst.setVisible(true);// 设置窗体可见,否则有时显示不出来
inst.setResizable(false);
}
public computter1() {
super();
initGUI();
}
private void initGUI() {
try {
{
ii=0;
// 实例化两个数组
double jb[] = new double [20];
double sqr[] = new double[20];
// 设置面板中组件的排列方式为手动排列
getContentPane().setLayout(null);
// 设置面板的背景颜色
getContentPane().setBackground(
new java.awt.Color(222, 231, 230));
// 设置窗体的标题
this.setTitle("\u8ba1\u7b97\u5668");
{
// 实例化标签
display = new JLabel();
// 把标签往面板上添加
getContentPane().add(display);
// 设置标签上显示的文本
display.setText("0.");
// 设置标签显示的位置,用坐标的方式
display.setBounds(14, 7, 357, 28);
// 设置标签的背景颜色
display.setBackground(new java.awt.Color(255, 255, 255));
display.setBorder(new LineBorder(
new java.awt.Color(0, 0, 0), 1, false));
}
{
// 实例化按钮
jb1 = new JButton();
// 往面板中添加按钮
getContentPane().add(jb1);
// 设置按钮显示的文本
jb1.setText("backspace");
// 设置按钮显示的位置,以坐标的方式
jb1.setBounds(28, 42, 105, 28);
// 为按钮添加事件处理机制
// 事件处理机制委托事件源委托监听者调用事件处理方法
jb1.addActionListener(this);
}
{
jb2 = new JButton();
getContentPane().add(jb2);
jb2.setText("CE");
jb2.setBounds(140, 42, 56, 28);
jb2.addActionListener(this);
}
{
jb3 = new JButton();
getContentPane().add(jb3);
jb3.setText("1/x");
jb3.setBounds(210, 42, 63, 28);
jb3.addActionListener(this);
}
{
jb4 = new JButton();
getContentPane().add(jb4);
jb4.setText("-");
jb4.setBounds(287, 42, 56, 28);
jb4.addActionListener(this);
}
{
jb5 = new JButton();
getContentPane().add(jb5);
jb5.setText("1");
jb5.setBounds(49, 77, 84, 28);
jb5.addActionListener(this);
}
{
jb6 = new JButton();
getContentPane().add(jb6);
jb6.setText("2");
jb6.setBounds(140, 77, 56, 28);
jb6.addActionListener(this);
}
{
jb7 = new JButton();
getContentPane().add(jb7);
jb7.setText("3");
jb7.setBounds(210, 77, 56, 28);
jb7.addActionListener(this);
}
{
jb8 = new JButton();
getContentPane().add(jb8);
jb8.setText("/");
jb8.setBounds(273, 77, 56, 28);
jb8.addActionListener(this);
}
{
jb9 = new JButton();
getContentPane().add(jb9);
jb9.setText("4");
jb9.setBounds(49, 112, 84, 28);
jb9.addActionListener(this);
}
{
jb10 = new JButton();
getContentPane().add(jb10);
jb10.setText("5");
jb10.setBounds(140, 112, 56, 28);
jb10.addActionListener(this);
}
{
jb11 = new JButton();
getContentPane().add(jb11);
jb11.setText("6");
jb11.setBounds(210, 112, 56, 28);
jb11.addActionListener(this);
}
{
jb12 = new JButton();
getContentPane().add(jb12);
jb12.setText("*");
jb12.setBounds(273, 112, 56, 28);
jb12.addActionListener(this);
}
{
jb13 = new JButton();
getContentPane().add(jb13);
jb13.setText("7");
jb13.setBounds(49, 147, 84, 28);
jb13.addActionListener(this);
}
{
jb14 = new JButton();
getContentPane().add(jb14);
jb14.setText("8");
jb14.setBounds(140, 147, 56, 28);
jb14.addActionListener(this);
}
{
jb15 = new JButton();
getContentPane().add(jb15);
jb15.setText("9");
jb15.setBounds(210, 147, 56, 28);
jb15.addActionListener(this);
}
{
jb16 = new JButton();
getContentPane().add(jb16);
jb16.setText("+");
jb16.setBounds(273, 147, 56, 28);
jb16.addActionListener(this);
}
{
jb17 = new JButton();
getContentPane().add(jb17);
jb17.setText("0");
jb17.setBounds(49, 182, 84, 28);
jb17.addActionListener(this);
}
{
jb18 = new JButton();
getContentPane().add(jb18);
jb18.setText("+/-");
jb18.setBounds(140, 182, 56, 28);
jb18.addActionListener(this);
}
{
jb19 = new JButton();
getContentPane().add(jb19);
jb19.setText(".");
jb19.setBounds(210, 182, 56, 28);
jb19.addActionListener(this);
}
{
jb20 = new JButton();
getContentPane().add(jb20);
jb20.setText("=");
jb20.setBounds(273, 182, 56, 28);
jb20.addActionListener(this);
}
}
this.setSize(407, 331);
{ //实例化一个菜单条,菜单必须放在菜单条当中
jMenuBar1 = new JMenuBar();
setJMenuBar(jMenuBar1);
{ //实例化一个菜单
bj = new JMenu();
//把菜单放在菜单条当中
jMenuBar1.add(bj);
//设置菜单显示的文本
bj.setText("编辑");
//获得组件的首选大小
bj.setPreferredSize(new java.awt.Dimension(35, 21));
{//生成菜单对象
copy = new JMenuItem();
//把菜单对象添加到菜单中
bj.add(copy);
//设置菜单显示的文本
copy.setText("复制");
//为菜单添加监听器
copy.addActionListener(this);
}
{
zt= new JMenuItem();
bj.add(zt);
zt.setText("粘贴");
zt.addActionListener(this);
}
}
{
exit = new JMenu();
jMenuBar1.add(exit);
exit.setText("文件");
{
del = new JMenuItem();
exit.add(del);
del.setText("退出");
del.setBounds(0, -21, 28, 21);
del.addActionListener(this);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e) {
//取出标签中的值�