当前位置: 代码迷 >> Java相关 >> SOS!
  详细解决方案

SOS!

热度:253   发布时间:2005-06-26 16:16:00.0
SOS!
偶是刚学的java,偶们老师让偶们编个计算器,偶编了个却老是说偶有错误,请哪位帅哥美女帮忙看一下,谢谢!在线等待!!
// NewMiniCalculator.java

import java.awt.*;
import java.applet.*;
public class computer extends Applet  {
    // 1 = '+', 2 = '-', 3 = '*', 4 = '/', 5 = '=', 0 = 其他?
    int Operation, LastButtonType;
    // 计算器的数字资料存储变量
    long OnScreen=0, OutOfScreen=0;
    // 计算器的Label参考值?
    TextField lblDisplay;

    public void init()  {
      
        // 把applet的尺寸改为130 * 160
        resize(180,160);

        // 产生计算器的输出显示
      
        lblDisplay = new TextField(String.valueOf(OnScreen),20);
        
       add(lblDisplay);

        
        // 产生计算器键盘
        CalculatorKeyBoard CKB = new CalculatorKeyBoard();
      
        add(CKB);

        // 重置计算器的状态
        resetCalculator();
    }

    public boolean keyDown(Event evt,int key){
    if (evt.KeyEvent instanceof button) {
          ?
            Char pkey=(Char)pkey;

            if (pkey.equals("C"))
                resetCalculator();
            else if (pkey.equals("+"))
                    setOperation(1);
                else if (pkey.equals("-"))
                    setOperation(2);
                    else if (pkey.equals("*"))
                         setOperation(3);
                         else if (pkey.equals("/"))
                              setOperation(4);
                              else if (pkey.equals("="))
                                   doOperation();
                                   else {
                                    if (LastButtonType == 0)
                                          OnScreen = OnScreen * 10L + Long.valueOf(pkey).longValue();
                                    else
                                          OnScreen = Long.valueOf(pkey).longValue();
                                    LastButtonType = 0;}
     // 设置新的显示字符串
            lblDisplay.setText(String.valueOf(OnScreen));
            return true;
        }
        else
            return false;
    }
    public boolean action(Event evt, Object what)   {
        // 只处理Button 所产生的action, 其他的不管?
        if (evt.target instanceof Button) {
            // 在Button的action中, what 只是该 Button上的文字??
            String targetLabel = (String)what;

            if (targetLabel.equals("C"))
                resetCalculator();
            else if (targetLabel.equals("+"))
                    setOperation(1);
                else if (targetLabel.equals("-"))
                    setOperation(2);
                    else if (targetLabel.equals("*"))
                         setOperation(3);
                         else if (targetLabel.equals("/"))
                              setOperation(4);
                              else if (targetLabel.equals("="))
                                   doOperation();
                                   else {
                                    if (LastButtonType == 0)
                                          OnScreen = OnScreen * 10L + Long.valueOf(targetLabel).longValue();
                                    else
                                          OnS
提示说我36行~就是KEYDOWN类下的if (evt.KeyEvent instanceof button) 出错了
搜索更多相关的解决方案: SOS  

----------------解决方案--------------------------------------------------------
  相关解决方案