楼主,能否转发给小弟,谢谢
[email protected]
我也初学

解决方案 »

  1.   

    fxywkj(胡言乱语,不必当真) ( ) 信誉:100  2004-09-04 11:15:00  得分: 0  
     
     
       楼主,能否转发给小弟,谢谢
    [email protected]
    我也初学
      
     I have send to you !!!!
      

  2.   

    也麻烦楼主或zhongzuo1981兄能发份给我,好让我也学习下,谢谢
    [email protected]
      

  3.   

    zhongzuo1981 (20)、 Thank you very much!!!
      

  4.   

    // 简单计算器import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;/*
    <applet code="jsq.class" width=230 height=280>
    </applet>
    */public class jsq01 extends Applet implements ActionListener
    {
        String Bu="1234567890+-*/=C";
        Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b0,Badd,Bsub,Bmul,Bdiv,Bva,Bcls;
        TextField Txt1;
        Font font1=new Font("宋体字14 point PLAIN",Font.PLAIN,20);
        
        long temp=-1;
        int ope=0,L=1;    public void paint(Graphics g)
        {
            g.setFont(font1);
            g.drawString("简 单 计 算 器",50,20);
        }    public void init()
        {
            setLayout(null);
            b1=new Button("1");
            b2=new Button("2");
            b3=new Button("3");
            b4=new Button("4");
            b5=new Button("5");
            b6=new Button("6");
            b7=new Button("7");
            b8=new Button("8");
            b9=new Button("9");
            b0=new Button("0");
            Badd=new Button("+");
            Bsub=new Button("-");
            Bmul=new Button("*");
            Bdiv=new Button("/");
            Bva=new Button("=");
            Bcls=new Button("C");
            Txt1=new TextField("");
            Txt1.setEditable(true);
            add(Txt1);
            Txt1.setBounds(20,40,190,25);
            
            add(b1);
            add(b2);
            add(b3);
            add(b4);
            add(b5);
            add(b6);
            add(b7);
            add(b8);
            add(b9);
            add(b0);
            add(Badd);
            add(Bsub);
            add(Bmul);
            add(Bdiv);
            add(Bva);
            add(Bcls);
        //设置按钮位置
            b1.setBounds(20,70,40,40);
            b2.setBounds(70,70,40,40);
            b3.setBounds(120,70,40,40);
            b4.setBounds(20,120,40,40);
            b5.setBounds(70,120,40,40);
            b6.setBounds(120,120,40,40);
            b7.setBounds(20,170,40,40);
            b8.setBounds(70,170,40,40);
            b9.setBounds(120,170,40,40);
            b0.setBounds(20,220,40,40);
            Badd.setBounds(170,70,40,40);
            Bsub.setBounds(170,120,40,40);
            Bmul.setBounds(170,170,40,40);
            Bdiv.setBounds(70,220,40,40);
            Bva.setBounds(120,220,40,40);
            Bcls.setBounds(170,220,40,40);
            
        //加入监事件
            b1.addActionListener(this);
            b2.addActionListener(this);
            b3.addActionListener(this);
            b4.addActionListener(this);
            b5.addActionListener(this);
            b6.addActionListener(this);
            b7.addActionListener(this);
            b8.addActionListener(this);
            b9.addActionListener(this);
            b0.addActionListener(this);
            Badd.addActionListener(this);
            Bsub.addActionListener(this);
            Bmul.addActionListener(this);
            Bdiv.addActionListener(this);
            Bva.addActionListener(this);
            Bcls.addActionListener(this);    }    public void actionPerformed(ActionEvent e)
        {
            switch (Bu.indexOf(e.getActionCommand())+1)
            {
                case 1:
                    if (L==0)
                    {
                        Txt1.setText("");
                        L=1;
                    }
                    Txt1.setText(Txt1.getText()+"1");
                    break;
                case 2:
                    if (L==0)
                    {
                        Txt1.setText("");
                        L=1;
                    }
                    Txt1.setText(Txt1.getText()+"2");
                    break;
                case 3:
                    if (L==0)
                    {
                        Txt1.setText("");
                        L=1;
                    }
                    Txt1.setText(Txt1.getText()+"3");
                    break;
                case 4:
                    if (L==0)
                    {
                        Txt1.setText("");
                        L=1;
                    }
                    Txt1.setText(Txt1.getText()+"4");
                    break;
                case 5:
                    if (L==0)
                    {
                        Txt1.setText("");
                        L=1;
                    }
                    Txt1.setText(Txt1.getText()+"5");
                    break;
                case 6:
                    if (L==0)
                    {
                        Txt1.setText("");
                        L=1;
                    }
                    Txt1.setText(Txt1.getText()+"6");
                    break;
                case 7:
                    if (L==0)
                    {
                        Txt1.setText("");
                        L=1;
                    }
                    Txt1.setText(Txt1.getText()+"7");
                    break;
                case 8:
                    if (L==0)
                    {
                        Txt1.setText("");
                        L=1;
                    }
                    Txt1.setText(Txt1.getText()+"8");
                    break;
                case 9:
                    if (L==0)
                    {
                        Txt1.setText("");
                        L=1;
                    }
                    Txt1.setText(Txt1.getText()+"9");
                    break;
                case 10:
                    if (L==0)
                    {
                        Txt1.setText("");
                        L=1;
                    }
                    Txt1.setText(Txt1.getText()+"0");
                    break;
                case 11:    // + 加
                    ope=11;
                    if (temp!=-1)
                        account(ope);
                    else
                    {
                        temp=Long.parseLong(Txt1.getText());
                        Txt1.setText("");
                    }
                    L=0;
                    break;
                case 12:    // - 减
                    ope=12;
                    if (temp!=-1)
                        account(ope);
                    else
                    {
                        temp=Long.parseLong(Txt1.getText());
                        Txt1.setText("");
                    }
                    L=0;
                    break;
                case 13:    // * 乘
                    ope=13;
                    if (temp!=-1)
                        account(ope);
                    else
                    {
                        temp=Long.parseLong(Txt1.getText());
                        Txt1.setText("");
                    }
                    L=0;
                    break;
                case 14:    // / 除
                    ope=14;
                    if (temp!=-1)
                        account(ope);
                    else
                    {
                        temp=Long.parseLong(Txt1.getText());
                        Txt1.setText("");
                    }
                    L=0;
                    break;
                case 15:    // = 等于
                    if (temp!=-1)
                        account(ope);
                    else
                        Txt1.setText("0");
                    L=1;
                    break;
                case 16:    // C 清除
                    Txt1.setText("");
                    temp=-1;
                    ope=0;
                    L=1;
                    break;
            }
        }    //按不同的运算符进行计算
        private void account(int o)
        {
            long t;
            t=Long.parseLong(Txt1.getText());
            switch (o)
            {
                case 11:    // + 加
                    temp=temp+t;
                    Txt1.setText(String.valueOf(temp));
                    break;
                case 12:    // - 减
                    temp=temp-t;
                    Txt1.setText(String.valueOf(temp));
                    break;
                case 13:    // * 乘
                    temp=temp*t;
                    Txt1.setText(String.valueOf(temp));
                    break;
                case 14:    // / 除
                    if (t==0)
                        Txt1.setText("0");
                    else
                    {
                        temp=temp/t;
                        Txt1.setText(String.valueOf(temp));
                    }
                    break;
            }    }