用java做一个简单的计算器
我是java初学者,尝试做一个简单的计算器,但运行会产生异常,而且得不到运算结果,请各位高手指点...程序如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
class 布局 extends Frame implements ActionListener
{ TextField text;
Button button1,button2,button3,button4;
Button button5,button6,button7,button8;
Button button9,button10,button11,button12;
Button button13,button14,button15,button16;
Panel panel1,panel2;
Box boxv1,boxv2,boxv3,boxv4;
Box boxh1,boxh2,boxh3,boxh4;
Font font=new Font("黑体",Font.BOLD,15);
布局()
{ setTitle("计算器");
text=new TextField("0",10);
Button button1=new Button("7");
button2=new Button("4");
button3=new Button("1");
button4=new Button("0");
button5=new Button("8");
button6=new Button("5");
button7=new Button("2");
button8=new Button("c");
button9=new Button("9");
button10=new Button("6");
button11=new Button("3");
button12=new Button("=");
button13=new Button("+");
button14=new Button("-");
button15=new Button("*");
button16=new Button("/");
button1.setForeground(Color.blue);
button2.setForeground(Color.blue);
button3.setForeground(Color.blue);
button4.setForeground(Color.blue);
button5.setForeground(Color.blue);
button6.setForeground(Color.blue);
button7.setForeground(Color.blue);
button8.setForeground(Color.red);
button9.setForeground(Color.blue);
button10.setForeground(Color.blue);
button11.setForeground(Color.blue);
button12.setForeground(Color.red);
button13.setForeground(Color.red);
button14.setForeground(Color.red);
button15.setForeground(Color.red);
button16.setForeground(Color.red);
button1.setFont(font);
button2.setFont(font);
button3.setFont(font);
button4.setFont(font);
button5.setFont(font);
button6.setFont(font);
button7.setFont(font);
button8.setFont(font);
button9.setFont(font);
button10.setFont(font);
button11.setFont(font);
button12.setFont(font);
button13.setFont(font);
button14.setFont(font);
button15.setFont(font);
button16.setFont(font);
Panel panel1=new Panel();
Panel panel2=new Panel();
panel1.setBackground(Color.blue);
panel2.setBackground(Color.blue);
boxv1=Box.createVerticalBox();
boxv2=Box.createVerticalBox();
boxv3=Box.createVerticalBox();
boxv4=Box.createVerticalBox();
boxv1.add(button1);
boxv1.add(Box.createVerticalStrut(8));
boxv1.add(button2);
boxv1.add(Box.createVerticalStrut(8));
boxv1.add(button3);
boxv1.add(Box.createVerticalStrut(8));
boxv1.add(button4);
boxv2.add(button5);
boxv2.add(Box.createVerticalStrut(8));
boxv2.add(button6);
boxv2.add(Box.createVerticalStrut(8));