展开全部
importjava.awt.*;importjava.awt.event.*;importjava.lang.*;importjavax.swing.*;publicclassCounterextendsFrame{//声明三个面板的布局GridLayoutgl1,gl2,gl3;Panelp0,p1,p2,p3;JTextFieldtf1;TextFieldtf2;Buttonb0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26;StringBufferstr;//显示屏所显示的字符串doublex,y;//x和y都是运算数intz;//Z表示32313133353236313431303231363533e58685e5aeb931333363386132单击了那一个运算符.0表示"+",1表示"-",2表示"*",3表示"/"staticdoublem;//记忆的数字publicCounter(){gl1=newGridLayout(1,4,10,0);//实例化三个面板的布局gl2=newGridLayout(4,1,0,15);gl3=newGridLayout(4,5,10,15);tf1=newJTextField(27);//显示屏tf1.setHorizontalAlignment(JTextField.RIGHT);tf1.setEnabled(false);tf1.setText("0");tf2=newTextField(10);//显示记忆的索引值tf2.setEditable(false);//实例化所有按钮、设置其前景色并注册监听器b0=newButton("Backspace");b0.setForeground(Color.red);b0.addActionListener(newBt());b1=newButton("CE");b1.setForeground(Color.red);b1.addActionListener(newBt());b2=newButton("C");b2.setForeground(Color.red);b2.addActionListener(newBt());b3=newButton("MC");b3.setForeground(Color.red);b3.addActionListener(newBt());b4=newButton("MR");b4.setForeground(Color.red);b4.addActionListener(newBt());b5=newButton("MS");b5.setForeground(Color.red);b5.addActionListener(newBt());b6=newButton("M+");b6.setForeground(Color.red);b6.addActionListener(newBt());b7=newButton("7");b7.setForeground(Color.blue);b7.addActionListener(newBt());b8=newButton("8");b8.setForeground(Color.blue);b8