求助 谁给我一个FLEX编写的简单的可以实现“+-*/”的计算器的代码啊
谢谢了
------解决方案--------------------
没人回啊,我随手给你写个吧,具体计算自己去实现吧!我用的flex4
- XML code
<?xml version="1.0" encoding="utf-8"?><s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="170" height="218" initialize="init()"> <fx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.ResizeEvent; import spark.components.Button; private var label:String = "789/456*123-0C=+"; private var maxChat:int = 20; [Bindable] private var _numA:Number; [Bindable] private var _numB:Number; private var _sign:int; private function init():void { display.editable = false; display.setStyle("direction","rtl"); this.addEventListener(KeyboardEvent.KEY_DOWN,keyDown); for(var i:int=0;i<label.length;i++){ var b:Button = new Button(); b.label = label.charAt(i); b.width=40; b.height=40; b.addEventListener(MouseEvent.CLICK,input); tg.addElement(b); } } private function input(e:MouseEvent):void { if(isNaN(e.target.label)){ control(e.target.label); }else{ if(display.text.length < maxChat) display.text=="0"?display.text = e.target.label:display.text += e.target.label; } } private function control(input:String):void { if(display.text == "0") return; if(!_numA) _numA = Number(display.text); else _numB = Number(display.text); switch(input){ case "C": break; case "+": break; case "-": break; case "*": break; case "/": break; case "=": break; } } private function keyDown(e:KeyboardEvent):void { //捕捉键盘按钮 } ]]> </fx:Script> <fx:Declarations> </fx:Declarations> <s:TextArea text="0" id="display" x="1" y="1" height="25" width="99%" /> <s:TileGroup id="tg" x="1" y="27" horizontalGap="2" verticalGap="2" requestedColumnCount="4" /> </s:WindowedApplication>