| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 573 人关注过本帖
标题:SOS!
只看楼主 加入收藏
wht006
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-6-26
收藏
 问题点数:0 回复次数: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 
2005-06-26 16:16
快速回复:SOS!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041877 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved