import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
public class Test4
{
public static void main(String[] args)
{
MyFrame f=new MyFrame();
f.setTitle("简易计算器。。。。。");
f.setSize(500,500);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
class MyFrame extends JFrame implements ActionListener
{
JPanel p1=new JPanel();
Font font1=new Font("Serif",3,45);
JButton b1=new JButton("1");
JButton b2=new JButton("2");
JButton b3=new JButton("3");
JButton b4=new JButton("4");
JButton b5=new JButton("5");
JButton b6=new JButton("6");
JButton b7=new JButton("7");
JButton b8=new JButton("8");
JButton b9=new JButton("9");
JButton b0=new JButton("0");
JButton ba=new JButton("+");
JButton bb=new JButton("-");
JButton bc=new JButton("*");
JButton bd=new JButton("/");
JButton be=new JButton("=");
JButton bf=new JButton("CE");
JPanel p=new JPanel();
JPanel p2=new JPanel();
JLabel l1=new JLabel();
StringBuffer s1=new StringBuffer();
StringBuffer s2=new StringBuffer();
StringBuffer sall=new StringBuffer();
String x=new String();
int f=0;
public MyFrame()
{
p1.setBackground(Color.pink);
p1.setLayout(new GridLayout(4,4,10,10));
b1.setBackground(Color.gray);
b1.setFont(font1);
b2.setBackground(Color.gray);
b2.setFont(font1);
b3.setBackground(Color.gray);
b3.setFont(font1);
b4.setBackground(Color.gray);
b4.setFont(font1);
b5.setBackground(Color.gray);
b5.setFont(font1);
b6.setBackground(Color.gray);
b6.setFont(font1);
b7.setBackground(Color.gray);
b7.setFont(font1);
b8.setBackground(Color.gray);
b8.setFont(font1);
b9.setBackground(Color.gray);
b9.setFont(font1);
b0.setBackground(Color.gray);
b0.setFont(font1);
ba.setBackground(Color.gray);
ba.setFont(font1);
bb.setBackground(Color.gray);
bb.setFont(font1);
bc.setBackground(Color.gray);
bc.setFont(font1);
bd.setBackground(Color.gray);
bd.setFont(font1);
be.setBackground(Color.gray);
be.setFont(font1);
bf.setBackground(Color.gray);
bf.setFont(font1);
p1.add(b1);
p1.add(b2);
p1.add(b3);
p1.add(b4);
p1.add(b5);
p1.add(b6);
p1.add(b7);
p1.add(b8);
p1.add(b9);
p1.add(b0);
p1.add(ba);
p1.add(bb);
p1.add(bc);
p1.add(bd);
p1.add(be);
p1.add(bf);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b0.addActionListener(this);
ba.addActionListener(this);
bb.addActionListener(this);
bc.addActionListener(this);
bd.addActionListener(this);
be.addActionListener(this);
bf.addActionListener(this);
add(p1,BorderLayout.SOUTH);
p.setBackground(Col
or.lightGray);
l1.setFont(font1);
l1.setText(sall.toString());
p.add(l1);
add(p,BorderLayout.CENTER);
p2.setBackground(Color.pink);
p2.add(new JLabel("简易计算器"));
add(p2,BorderLayout.NORTH);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1)
{
sall.append("1");
l1.setText(sall.to