//calculator!! by Rocky  Oct 7th 2003.
//MOS SoftWare Engineering   Class 5 & M00561513  WangJianimport java.applet.Applet;
import java.awt.*; //applet,并非应用程序。public class Calc2 extends Applet
{  
//定义16个屏幕按钮 Button按钮的具体位置无法设定!!
  private Button b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, bMin, bMul, bAdd, bDiv, bDot, bEqu ;
  private TextField outPut;
    public void init()
  {            outPut = new TextField ( 300 );    b7 = new Button ( "7" ); // 7 8 9 /
    b8 = new Button ( "8" ); // 4 5 6 *
    b9 = new Button ( "9" ); // 1 2 3 -
    bDiv = new Button ( "/" ); // 0 . = +
   
    b4 = new Button ( "4" );
    b5 = new Button ( "5" );
    b6 = new Button ( "6" );
    bMul = new Button ( "*" );
    
    b1 = new Button ( "1" );
    b2 = new Button ( "2" );
    b3 = new Button ( "3" );
    bMin = new Button ( "-" );    b0 = new Button ( "0" );
    bDot = new Button ( "." );
    bEqu = new Button ( "=" );
    bAdd = new Button ( "+" );   // add ( outPut );    setLayout ( new GridLayout ( 4, 4, 3, 3 ) );    add ( b7 );
    add ( b8 );
    add ( b9 );
    add ( bDiv );    add ( b4 );
    add ( b5 );
    add ( b6 );
    add ( bMul );
 
    add ( b1 );
    add ( b2 );
    add ( b3 );
    add ( bMin );    add ( b0 );
    add ( bDot );
    add ( bEqu );
    add ( bAdd );
  } //处理按钮事件
/*
  public boolean action ( Event e, Object o )
  {
    return true;
  } */  public void paint ( Graphics g )
  {  }  }其实,关于模拟计算器的关键在两个地方:
1、在模拟的显示效果中,如何实现连续数字的输入。
2、异常处理。如果用swing的图形界面,感觉就是将很多method换成其他的形势(和awt中类似的,名称不同罢了)如果,编写的是application,需要改变的有哪些呢?这是本人尝试做的第一个java applet, 期待交流。                                                     ——jiansmile