用Flex写的一个简单计算器

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"    layout="absolute" height="620" borderColor="#FD9706"  textAlign="center" width="1072">

   <mx:Panel x="10" y="10" width="560" height="372"      layout="absolute"borderColor="#FADA05"  backgroundColor="#CE0FF7" title="计算器" fontSize="20" fontStyle="normal" fontGridFitType="none" fontAntiAliasType="normal" themeColor="#F61414" textDecoration="none" verticalAlign="middle" fontWeight="bold">
  

<mx:Script>
   <![CDATA[
    import mx.messaging.SubscriptionInfo;
       static private var a:Array=new Array();
    private function button_clicked(event:Event):void
    {
     if(event.target.id== "button_1")                    {    input.text+="1";                       }
     else if(event.target.id == "button_2")
      {
           input.text+="2";
      }
     else if(event.target.id == "button_3")
     {
          input.text+="3";
      }
      else if(event.target.id == "button_4")
      {
          input.text+="4";
      }
      else if(event.target.id == "button_5")
      {
          input.text+="5";
      }
      else if(event.target.id == "button_6")
      {
          input.text+="6";
      }
      else if(event.target.id == "button_7")
      {
          input.text+="7";
       }
       else if(event.target.id == "button_8")
       {
            input.text+="8";
       }
       else if(event.target.id == "button_9")
       {
            input.text+="9";
       }
       else if(event.target.id == "button_0")
       {
            input.text+="0";
       }
       else if(event.target.id == "button_clear")
       {
            input.text="";
              while(a.length>0)
                  a.pop();
       }                   
    }
    private function jisuan():void
    { /*   
     switch(a[a.length-2])
     {
         a.push(input.text);
         if(a[a.length-2]=="+")
             input.text=Number(a[a.length-3])+Number(a[a.length-1])+"";
         else if(a[a.length-2]=="-")
             input.text=Number(a[a.length-3])-Number(a [a.length-1])+"";        
         else if(a[a.length-2]=="×")
              input.text=Number(a[a.length-3])*Number(a[a.length-1])+"";
     else if(a[a.length-2]=="÷")
        input.text=Number(a[a.length-3])/Number(a[a.length-1])+"";
        a.push(input.text);               
    }
   ]]>
  </mx:Script>    
  

   <mx:TextInput id="input" x="23" y="10" width="249" height="43" fontSize="35" backgroundColor="#A3E90D"/>
  

   <mx:Button x="23" y="71" id="button_1" label="1" click="button_clicked(event)" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
 

   <mx:Button x="82" y="71" label="2" id="button_2" click="button_clicked(event)" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
  

   <mx:Button x="153" y="71" label="3" id="button_3" click="button_clicked(event)" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
 

   <mx:Button x="23" y="114" label="4" id="button_4" click="button_clicked(event)" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
  

   <mx:Button x="85" y="114" label="5" id="button_5" click="button_clicked(event)" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
  

   <mx:Button x="153" y="114" label="6" id="button_6" click="button_clicked(event)" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
  

   <mx:Button x="23" y="157" label="7" id="button_7" click="button_clicked(event)" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
  

   <mx:Button x="82" y="157" label="8" id="button_8" click="button_clicked(event)" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
  

   <mx:Button x="153" y="157" label="9" id="button_9" click="button_clicked(event)" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
  

   <mx:Button x="23" y="200" label="0" id="button_0" click="button_clicked(event)" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
  
  <mx:Button x="221" y="71" label="+" id="button_add" click="a.push(input.text),a.push('+'),input.text=''" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
 

   <mx:Button x="221" y="114" label="-" id="button_sub" click="a.push(input.text),a.push('-'),input.text=''" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
  

   <mx:Button x="221" y="157" label="×" id="button_mul" click="a.push(input.text),a.push('×'),input.text=''" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
  

   <mx:Button x="221" y="200" label="÷" id="button_div" click="a.push(input.text),a.push('÷'),input.text=''" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
  
    
  <mx:Button x="153" y="200" label="=" id="button_equal" click="jisuan()" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
  
  <mx:Button x="82" y="200" label="C" id="button_clear" click="button_clicked(event)" fillAlphas="[1.0, 1.0, 1.0, 1.0]" fillColors="[#E708FB, #F60808]" height="35" width="51" fontSize="25"/>
 </mx:Panel>
</mx:Application>

效果图如下:


这是本人学习Flex写的第一个程序,有点粗糙,但还是可以进行基本的计算的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值