| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 662 人关注过本帖
标题:哪位大哥帮忙看一下我的程序为什么运行不了!!!!!!!!!!
只看楼主 加入收藏
learnerboy
Rank: 2
等 级:论坛游民
帖 子:246
专家分:22
注 册:2007-11-11
结帖率:100%
收藏
 问题点数:0 回复次数:3 
哪位大哥帮忙看一下我的程序为什么运行不了!!!!!!!!!!
//用APPLET实现简单计算器
import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Computer extends Applet implements ActionListener {
    /**
     *
     */
    private static final long serialVersionUID = 0L;

    int a = 0, b = 0, point, p = 0;

    float c = 0;

    String symbol = "", str = "";

    TextField result;

    Button bt1, bt2, bt3, bt4, bt5;

    Button bt6, bt7, bt8, bt9, bt0;

    Button bt_add, bt_plus, bt_multiply, bt_divide, bt_eqauls;

    public void init() {
        // TODO 自动生成方法存根
        super.init();
        result = new TextField(10);
        result.setText("");
        bt1 = new Button("1");
        bt2 = new Button("2");
        bt3 = new Button("3");
        bt4 = new Button("4");
        bt5 = new Button("5");
        bt6 = new Button("6");
        bt7 = new Button("7");
        bt8 = new Button("8");
        bt9 = new Button("9");
        bt0 = new Button("0");
        bt_add = new Button("+");
        bt_plus = new Button("-");
        bt_multiply = new Button("*");
        bt_divide = new Button("/");
        bt_eqauls = new Button("=");
        add(result);
        add(bt1);
        add(bt2);
        add(bt3);
        add(bt4);
        add(bt5);
        add(bt6);
        add(bt7);
        add(bt8);
        add(bt9);
        add(bt0);
        add(bt_add);
        add(bt_plus);
        add(bt_multiply);
        add(bt_divide);
        add(bt_eqauls);
        result.addActionListener(this);
        bt1.addActionListener(this);
        bt2.addActionListener(this);
        bt3.addActionListener(this);
        bt4.addActionListener(this);
        bt5.addActionListener(this);
        bt6.addActionListener(this);
        bt7.addActionListener(this);
        bt8.addActionListener(this);
        bt9.addActionListener(this);
        bt0.addActionListener(this);
        bt_add.addActionListener(this);
        bt_divide.addActionListener(this);
        bt_eqauls.addActionListener(this);
        bt_multiply.addActionListener(this);
        bt_plus.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) {
        // TODO 自动生成方法存根
        if(e.getSource()==bt1)
            str=result.getText()+bt1.getLabel();
        else if(e.getSource()==bt2)
            str=result.getText()+bt2.getLabel();
        else if(e.getSource()==bt3)
            str=result.getText()+bt3.getLabel();
        else if(e.getSource()==bt4)
            str=result.getText()+bt4.getLabel();
        else if(e.getSource()==bt5)
            str=result.getText()+bt5.getLabel();
        else if(e.getSource()==bt6)
            str=result.getText()+bt6.getLabel();
        else if(e.getSource()==bt7)
            str=result.getText()+bt7.getLabel();
        else if(e.getSource()==bt8)
            str=result.getText()+bt8.getLabel();
        else if(e.getSource()==bt9)
            str=result.getText()+bt9.getLabel();
        else if(e.getSource()==bt0)
            str=result.getText()+bt0.getLabel();
        result.setText(str);
        if(p==0){
            a=Integer.parseInt(result.getText());
            p++;
            result.setText("");
        }
        else{
            b=Integer.parseInt(result.getText());
            p++;
        }
        if(e.getSource()==bt_add){
            symbol="+";
            point=0;
            result.setText("");
        }
        else if(e.getSource()==bt_plus){
            symbol="-";
            point=1;
            result.setText("");
        }
        else if(e.getSource()==bt_multiply){
            symbol="*";
            point=2;
            result.setText("");
        }
        else if(e.getSource()==bt_divide){
            symbol="/";
            point=3;
            result.setText("");
        }
        if(p>1){
            switch (point) {
            case 0:
                c=a+b;
                result.setText(Float.toString(c));
                break;
            case 1:
                c=a-b;
                result.setText(Float.toString(c));
                break;
            case 2:
                c=a*b;
                result.setText(Float.toString(c));
                break;
            case 3:
                c=(float)(a/b);
                result.setText(Float.toString(c));
                break;
            }
        }    
    }
}
搜索更多相关主题的帖子: 运行 
2008-10-14 21:17
zacom
Rank: 2
等 级:论坛游民
威 望:2
帖 子:381
专家分:15
注 册:2007-9-15
收藏
得分:0 
说清楚点..是显示不出来.还是运算出错

没有最好只有更好
2008-10-14 22:10
learnerboy
Rank: 2
等 级:论坛游民
帖 子:246
专家分:22
注 册:2007-11-11
收藏
得分:0 
运算出错!它实现不了两个数的加,减,乘,除运算!
2008-10-15 06:35
zacom
Rank: 2
等 级:论坛游民
威 望:2
帖 子:381
专家分:15
注 册:2007-9-15
收藏
得分:0 
你不觉的还有别的问题吗。。输入数显示不出来,排版也不好。。要修改工程很大。。你自己再改进下吧

没有最好只有更好
2008-10-15 12:29
快速回复:哪位大哥帮忙看一下我的程序为什么运行不了!!!!!!!!!!
数据加载中...
 
   



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

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