---------------------- <a href="http://www.itheima.com"target="blank">ASP.Net+Unity开发</a>、<a href="http://www.itheima.com"target="blank">.Net培训</a>、期待与您交流! ----------------------
package JiSuanQi;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import javax.swing.*;
public class JiSuanQi extends JFrame implements ActionListener {
JButton b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15,
b16;
JFrame f;
JPanel p1=new JPanel();
GridLayout c = new GridLayout(4, 4);
BorderLayout b= new BorderLayout(0,0);
JTextField shuru = new JTextField();
JTextField xianshi = new JTextField();
String str3="";
String str1="";
String str2="";
String str4="";
String str5="";
double value1,value2,resoult=0;
public JiSuanQi(){
init();
}
public void init() {
f = new JFrame("计算器");
Container ct = f.getContentPane();
shuru.setHorizontalAlignment(JTextField.RIGHT);
xianshi.setHorizontalAlignment(JTextField.LEFT);
ct.add(p1,"North");
p1.setLayout(b);
p1.add(xianshi, "North");
p1.add(shuru,"Center");
JPanel p2 = new JPanel();
ct.add(p2, "Center");
GridLayout c = new GridLayout(4, 4,4,4);
p2.setLayout(c);
JButton b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16;
b1 = new JButton("1");
b2 = new JButton("2");
b3 = new JButton("3");
b4 = new JButton("4");
b5 = new JButton("5");
b6 = new JButton("6");
b7 = new JButton("7");
b8 = new JButton("8");
b9 = new JButton("9");
b10 = new JButton("0");
b11 = new JButton(".");
b12 = new JButton("=");
b13 = new JButton("+");
b14 = new JButton("-");
b15 = new JButton("*");
b16 = new JButton("/");
p2.add(b1);
b1.addActionListener(this);
p2.add(b2);
b2.addActionListener(this);
p2.add(b3);
b3.addActionListener(this);
p2.add(b13);
b13.addActionListener(this);
p2.add(b4);
b4.addActionListener(this);
p2.add(b5);
b5.addActionListener(this);
p2.add(b6);
b6.addActionListener(this);
p2.add(b14);
b14.addActionListener(this);
p2.add(b7);
b7.addActionListener(this);
p2.add(b8);
b8.addActionListener(this);
p2.add(b9);
b9.addActionListener(this);
p2.add(b15);
b15.addActionListener(this);
p2.add(b10);
b10.addActionListener(this);
p2.add(b11);
b11.addActionListener(this);
p2.add(b12);
b12.addActionListener(this);
p2.add(b16);
b16.addActionListener(this);
/* f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});*/
f.setSize(300, 250);
f.setVisible(true);