请位高手帮我注释下段代码,关键代码处标明中文意思,也就是翻译下代码的意思。是个JAVA 编的加减乘除计算器

小小菜鸟3 发布于 2012/03/14 17:01
阅读 599
收藏 0

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

 

public  class Shiyan

{

     

      String shu1="";

      String shu2="";

      double jg;

      String jieguo="";

      String yunsuanfu="";

      boolean one=true;

      boolean two=true;

      boolean three=true;

      boolean four=true;

 

     

      JFrame frame=new JFrame("计算器");

      JPanel panel1=new JPanel();

      JPanel panel2=new JPanel();

      JButton btn0=new JButton("0");

      JButton btn1=new JButton("1");

      JButton btn2=new JButton("2");

      JButton btn3=new JButton("3");

      JButton btn4=new JButton("4");

      JButton btn5=new JButton("5");

      JButton btn6=new JButton("6");

      JButton btn7=new JButton("7");

      JButton btn8=new JButton("8");

      JButton btn9=new JButton("9");

      JButton jia=new JButton("+");

      JButton jian=new JButton("-");

      JButton cheng=new JButton("x");

      JButton chu=new JButton("/");

      JButton dengyu=new JButton("=");

      JButton qingchu=new JButton("C");

      JTextField tf=new JTextField(20);

     

     

      public static void main(String args[])

      {

             new Shiyan();

      }

     

     

     

      Shiyan()

      {

             frame.add(panel1);

             frame.add(panel2);

             panel1.add(tf);

             panel2.add(btn7);

             panel2.add(btn8);

             panel2.add(btn9);

             panel2.add(jia);

             panel2.add(btn4);

             panel2.add(btn5);

             panel2.add(btn6);

             panel2.add(jian);

             panel2.add(btn1);

             panel2.add(btn2);

             panel2.add(btn3);

             panel2.add(cheng);

             panel2.add(btn0);

             panel2.add(qingchu);

             panel2.add(dengyu);

             panel2.add(chu);

            

             frame.setVisible(true);

             frame.setSize(300, 200);

             frame.setResizable(false);

             frame.setLocation(234, 345);

             frame.getContentPane().add(panel1,BorderLayout.NORTH);

             frame.getContentPane().add(panel2,BorderLayout.CENTER);

             panel1.setLayout(new GridLayout(1,1));

             panel2.setLayout(new GridLayout(4, 4));  //布局

            

            

            

             class Shuzi implements ActionListener                                            //数字键

             {

                    public void actionPerformed(ActionEvent e)

                    {

                           if(one==true)                           //one=true表示数字1可以输入

                                  {

                                         String input1=((JButton)e.getSource()).getText();

                                         shu1=shu1+input1;

                                         if(three==true)

                                         {

                                                tf.setText(shu1);

                                         }

                                  }

                                  else                                   //one=false数字1不可以输入,数字2可以输入

                                  {

                                        

                                         String input2=((JButton)e.getSource()).getText();

                                         tf.setText(null);

                                         shu2=shu2+input2;

                                        

                                         if(four==true)

                                         {

                                                tf.setText(shu2);

                                         }

                                  }

                    }

             }

            

             class Fuhao implements ActionListener                                        //运算符

             {

                    public void actionPerformed(ActionEvent e)

                    {

                           String input3=((JButton)e.getSource()).getText();

                           yunsuanfu=input3;

                           one=false;

                           tf.setText(yunsuanfu);          //four=true运算符可输入

                           three=false;

                    }

             }

            

             class Deng implements ActionListener

             {

                    public void actionPerformed(ActionEvent e)

                    {

                                  jusuan();

                                  tf.setText(jieguo);

                                  shu1=jieguo;

                    }

             }

            

            

             class Qingling implements ActionListener

             {

                    public void actionPerformed(ActionEvent e)

                    {

                           tf.setText(null);

                           shu1="";

                           shu2="";

                           yunsuanfu="";

                    }

             }

            

             /////注册

            

             Shuzi shu=new Shuzi();

             Fuhao fuhao=new Fuhao();

             Deng deng=new Deng();

             Qingling qingling=new Qingling();

            

             btn0.addActionListener(shu);

             btn1.addActionListener(shu);

             btn2.addActionListener(shu);

             btn3.addActionListener(shu);

             btn4.addActionListener(shu);

             btn5.addActionListener(shu);

             btn6.addActionListener(shu);

             btn7.addActionListener(shu);

             btn8.addActionListener(shu);

             btn9.addActionListener(shu);

             jia.addActionListener(fuhao);

             jian.addActionListener(fuhao);

             cheng.addActionListener(fuhao);

             chu.addActionListener(fuhao);

             dengyu.addActionListener(deng);

             qingchu.addActionListener(qingling);

      }

     

      public void jusuan()

      {

             double a;

             double b;

            

             a=Integer.parseInt(shu1);

             b=Integer.parseInt(shu2);

            

             if(yunsuanfu.equals("+"))

             {

                    jg=a+b;

             }

             else if(yunsuanfu.equals("-"))

             {

                    jg=a-b;

             }

             else if(yunsuanfu.equals("x"))

             {

                    jg=a*b;

             }

             else if(yunsuanfu.equals("/"))

             {

                    jg=a/b;

             }

             one=true;

             two=true;

             three=true;

             four=true;

             jieguo=(new  Double(jg).toString());

             tf.setText(jieguo);

      }

}

加载中
0
白黑白
白黑白

偷懒的孩子不是好孩子哟

小小菜鸟3
帮个忙啊~
0
Andre.Z
Andre.Z
貌似真没啥需要加注释的。
小小菜鸟3
呵呵~ 大致注释下 翻译下意思撒~ 谢谢咯
0
首席xx师
首席xx师
估计还没入门,在门外看这代码的确有点..........
小小菜鸟3
确实简单的很啊~ 能帮忙注释下意思就注释下啊
0
echor
echor
这段代码为什么要加注释???
小小菜鸟3
因为我需要注释下意思啊~帮个忙呗
返回顶部
顶部