咖啡伴侶

          呆在上海
          posts - 163, comments - 156, trackbacks - 0, articles - 2

               摘要:   閱讀全文

          posted @ 2008-04-08 12:11 oathleo 閱讀(2330) | 評論 (0)編輯 收藏

               摘要: Ext是一個非常好的Ajax框架,其華麗的外觀表現確實令我們折服,然而一個應用始終離開不服務器端,因此在實現開發中我們需要對Ext與服務器端的交互技術有較為詳細的了解,在開發中才能游刃有余地應用。本文對Ext應用中與服務器交互的常用方法作具體的介紹,本文的內容大部份來源于《ExtJS實用開發指南》。  總體來說,Ext與服務器端的交互應用可以歸結為三種類型,包含表單FormPanel的處理(提交、...  閱讀全文

          posted @ 2008-04-07 11:00 oathleo 閱讀(1585) | 評論 (1)編輯 收藏

               摘要:   閱讀全文

          posted @ 2008-03-28 10:11 oathleo 閱讀(1719) | 評論 (2)編輯 收藏

          /*
          * show the arthimetic character of '<<' '>>' '>>>'
          */

          public class TestArithmetic {
          ?? public TestArithmetic() {
          ?? }
          ??
          ?? public?? static void?? main(String [] args){
          ???? int minus = -10;
          ???? System.out.println(" Binary of -10 is " + Integer.toBinaryString(minus));
          ???? System.out.println(" Arthimetic minus by -10 << 2 = " + (minus<<2) + " Binary is " + Integer.toBinaryString(minus<<2));
          ???? System.out.println(" Arthimetic minus by -10 >> 2 = " + (minus>>2) + " Binary is " + Integer.toBinaryString(minus>>2));
          ???? System.out.println(" Arthimetic minus by -10 >>>2 =?? " + (minus >>> 2) + " Binary is " + Integer.toBinaryString(minus>>>2)
          ??????????????????????? + ",length is " + Integer.toBinaryString(minus>>>2).length());
          ????
          ???? int plus = 10;
          ???? System.out.println(" Binary of 10 is " + Integer.toBinaryString(plus));
          ???? System.out.println(" Arthimetic minus by 10 << 2 = " + (plus<<2)+ "Binary is " + Integer.toBinaryString(plus<<2));
          ???? System.out.println(" Arthimetic minus by 10 >> 2 = " + (plus>>2)+ "Binary is "+ Integer.toBinaryString(plus>>2));
          ???? System.out.println(" Arthimetic minus by 10 >>>2 =?? " + (plus >>> 2)+ "Binary is "+ Integer.toBinaryString(plus >>> 2));
          ?? }

          補充知識:數值的補碼表示也分兩種情況:
          (1)正數的補碼:與原碼相同。
          例如,+9的補碼是00001001。
          (2)負數的補碼:符號位為1,其余位為該數絕對值的原碼按位取反;然后整個數加1。
          例如,-7的補碼:因為是負數,則符號位為“1”,整個為10000111;其余7位為-7的絕對值+7的原碼0000111按位取反為1111000;再加1,所以-7的補碼是11111001。


          已知一個數的補碼,求原碼的操作分兩種情況:
          (1)如果補碼的符號位為“0”,表示是一個正數,所以補碼就是該數的原碼。
          (2)如果補碼的符號位為“1”,表示是一個負數,求原碼的操作可以是:符號位為1,其余各位取反,然后再整個數加1。
          例如,已知一個補碼為11111001,則原碼是10000111(-7):因為符號位為“1”,表示是一個負數,所以該位不變,仍為“1”;其余7位1111001取反后為0000110;再加1,所以是10000111。

          posted @ 2008-03-28 10:08 oathleo 閱讀(602) | 評論 (0)編輯 收藏

               摘要:   閱讀全文

          posted @ 2008-03-28 10:08 oathleo 閱讀(5928) | 評論 (7)編輯 收藏

          用XMLEncode輸出時候,如果有BigDecimal有時候不好使。
          原因是:如果類的變量在定義時候有初始值,而不是null,就必須要重載DefaultPersistenceDelegate的mutatesTo方法。
          關于這個說明,在網上這里可以看到:
          http://forum.java.sun.com/thread.jspa?threadID=631299&messageID=3642493

          有興趣的可以看看:
          //setup big decimal delegate.
          ????????? DefaultPersistenceDelegate bigDecimalDelegate = new DefaultPersistenceDelegate() {
          ????????????? protected Expression instantiate(Object oldInstance, Encoder out) {
          ????????????????? BigDecimal decimal = (BigDecimal) oldInstance;
          ????????????????? return new Expression(oldInstance, oldInstance.getClass(), "new", new Object[] {decimal.toString()});
          ????????????? }
          ????????????? //must override this method.
          ????????????? // see http://forum.java.sun.com/thread.jspa?threadID=631299&messageID=3642493
          ????????????? protected boolean mutatesTo(Object oldInstance, Object newInstance) {
          ????????????????? return oldInstance.equals(newInstance);
          ????????????? }
          ????????????? //--- Joshua
          ????????? };

          網上的牛人說:

          This works for BigDecimal properties that aren't initialized, i.e. null. But if you initialize the property, then this won't work unless you override mutatesTo in addition to instantiate mentioned above:

          protected boolean mutatesTo(Object oldInstance, Object newInstance) {
          return oldInstance.equals(newInstance);
          }

          posted @ 2008-03-28 10:07 oathleo 閱讀(545) | 評論 (0)編輯 收藏

          public class MethodDemo {

          /**
          * @param args
          */
          public static void main(String[] args) {
             MethodDemo demo = new MethodDemo();
             Integer i = Integer.valueOf(1);
             demo.add(i);
             System.out.println("i:" + i);
            
             String s = "ss";
             demo.stringchange(s);
             System.out.println("s:" + s);
            
             Person per = new Person();

              per.name = "per1";
             demo.setDate(per);
             System.out.println("per:" + per.getName());
          }

          //基本類型變不了
          public void add(int i) {
             i++;
          }

          /***
          * 凡是在引用中出現修改引用的賦值語句,
          * 修改都變成無效
          * @param i
          */

          //想修改引用,不行
          public void add(Integer i) {
             int j = i.intValue();
             i = Integer.valueOf(j++);//i的原引用已經丟失了
          }

          //想修改引用,不行
          public void stringchange(String s){
             s = "stringchange";
          }

          public void setDate(Person per){
             Person per2 = new Person();
             per2.setName("per2Name");
             per = per2;//per的原引用已經丟失了,這個估計很多人會出錯
             per.setName("name");
          }

          }

          class Person {
          String name ;

          public String getName() {
             return name;
          }

          public void setName(String name) {
             this.name = name;
          }

          }

          posted @ 2008-03-28 10:05 oathleo 閱讀(362) | 評論 (0)編輯 收藏

          <?xml version="1.0"?>
          <!-- usingas/AddingChildrenAsUIComponents.mxml -->
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
          ??? <mx:Script><![CDATA[
          ??????? import flash.display.Sprite;
          ??????? import mx.core.UIComponent;

          ??????? private var xLoc:int = 20;
          ??????? private var yLoc:int = 20;
          ??????? private var circleColor:Number = 0xFFCC00;

          ??????? private function addChildToPanel():void {

          ??????????? var circle:Sprite = new Sprite();
          ??????????? circle.graphics.beginFill(circleColor);
          ??????????? circle.graphics.drawCircle(xLoc, yLoc, 15);

          ??????????? var c:UIComponent = new UIComponent();
          ??????????? c.addChild(circle);
          ??????????? panel1.addChild(c);
          ???????????
          ??????????? xLoc = xLoc + 5;
          ??????????? yLoc = yLoc + 1;
          ??????????? circleColor = circleColor + 20;
          ??????? }
          ??? ]]></mx:Script>

          ??? <mx:Panel id="panel1" height="250" width="300" verticalScrollPolicy="off"/>

          ??? <mx:Button id="myButton" label="Click Me" click="addChildToPanel();"/>
          ???
          </mx:Application>

          posted @ 2008-03-28 10:00 oathleo 閱讀(444) | 評論 (0)編輯 收藏

          綁定的作用在于,將Flex中的變量、類、方法等與組件的值進行綁定。例如,一個變量如果被綁定后,那么引用該變量的組件的相關屬性也會發生改變。我們用一個實例來表示

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=http://www.adobe.com/2006/mxml layout="absolute" xmlns:components="components.*"
          ? ? ? >
          ? ? ? <mx:Script>
          ? ? ? ? ???<![CDATA[
          ? ? ? ? ? ? ? ???import mx.controls.Alert;? ? ? ? ? ?
          ? ? ? ? ? ? ? ???[Bindable]
          ? ? ? ? ? ? ? ???private var isSelected:Boolean;
          ? ? ? ? ? ? ? ???private function clickHandler(e:MouseEvent){
          ? ? ? ? ? ? ? ???//Alert.show(e.currentTarget.toString());
          ???????????????? isSelected=isSelected?false:true; //這句話的意思是如果isSelected為true,改變它為false,如果它為false,改變它為true;
          ?????????????????Alert.show(isSelected.toString());
          ? ? ? ? ? ? ? ???}
          ? ? ? ? ???]]>
          ? ? ? </mx:Script>
          ? ? ? <mx:Button id="testBtn"? click="clickHandler(event)" label="測試" />
          ? ? ? <mx:CheckBox x="60" selected="{isSelected}" />
          </mx:Application>

          上述程序的效果就是,當點擊button時,button不是直接改變checkbox的選中狀態,而是改變isSelected這個變量,由于isSelected是被綁定了的,那么會關聯的改變CheckBox的選中狀態。

          這樣看起來有些多此一舉,完全可以直接改變checkbox的selected屬性,我只是為了演示一下效果。如果說你的checkbox是動態構造的上百個,你不會去一個個的改變他吧。

          因此,我們多數會將一個數據源進行綁定聲明,這樣引用了這個數據源的控件,比如datagrid,在數據源發生了改變時,即使你不重新設置dataProvider,列表的數據也會刷新。

          posted @ 2008-03-28 09:59 oathleo 閱讀(479) | 評論 (1)編輯 收藏

          ?public class ColorLabel extends Label
          ?{
          ??private var colorValue:Number = -1;
          ??public function ColorLabel()
          ??{
          ???super();
          ??}
          ??
          ??public function setColorValue(colorValue:Number):void
          ??{
          ???this.colorValue = colorValue;
          ??}
          ??
          ??override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
          ???? {
          ??????????? super.updateDisplayList(unscaledWidth, unscaledHeight);
          ??????????? if(colorValue>=0){
          ??????????? ?drawColor(colorValue);
          ??????????? }
          ???? }
          ??
          ??private function drawColor(colorValue:Number):void
          ???? {
          ???? ?? this.graphics.beginFill(colorValue);
          ????????????? this.graphics.drawRect(this.textField.x,this.textField.y,this.textWidth ,this.textHeight);
          ????????????? this.graphics.endFill();
          ???? }
          ?}
          ?
          ?
          ?*? <p>In general, components do not override the <code>validateProperties()</code>,
          ?*? <code>validateSize()</code>, or <code>validateDisplayList()</code> methods
          .?
          ?*? In the case of UIComponents, most components override the
          ?*? <code>commitProperties()</code>, <code>measure()</code>, or
          ?*? <code>updateDisplayList()</code> methods
          , which are called
          ?*? by the <code>validateProperties()</code>,
          ?*? <code>validateSize()</code>, or
          ?*? <code>validateDisplayList()</code> methods, respectively.</p>
          ?
          ?

          ?

          Implementing the commitProperties() method

          You use the commitProperties() method to coordinate modifications to component properties. Most often, you use it with properties that affect how a component appears on the screen.

          Flex schedules a call to the commitProperties() method when a call to the invalidateProperties() method occurs. The commitProperties() method executes during the next render event after a call to the invalidateProperties() method. When you use the addChild() method to add a component to a container, Flex automatically calls the invalidateProperties() method.

          Calls to the commitProperties() method occur before calls to the measure() method. This lets you set property values that the measure() method might use.

          Implementing the measure() method

          The measure() method sets the default component size, in pixels, and optionally sets the component's default minimum size.

          Flex schedules a call to the measure() method when a call to the invalidateSize() method occurs. The measure() method executes during the next render event after a call to the invalidateSize() method. When you use the addChild() method to add a component to a container, Flex automatically calls the invalidateSize() method.

          Implementing the updateDisplayList() method

          The updateDisplayList() method sizes and positions the children of your component based on all previous property and style settings, and draws any skins or graphic elements that the component uses. The parent container for the component determines the size of the component itself.

          A component does not appear on the screen until its updateDisplayList() method gets called. Flex schedules a call to the updateDisplayList() method when a call to the invalidateDisplayList() method occurs. The updateDisplayList() method executes during the next render event after a call to the invalidateDisplayList() method. When you use the addChild() method to add a component to a container, Flex automatically calls the invalidateDisplayList() method.

          Drawing graphics in your component

          Every Flex component is a subclass of the Flash Sprite class, and therefore inherits the Sprite.graphics property. The Sprite.graphics property specifies a Graphics object that you can use to add vector drawings to your component.

          For example, in the updateDisplayList() method, you can use methods of the Graphics class to draw borders, rules, and other graphical elements:

          ?

          總結:

          修改屬性用commitProperties,自己畫用updateDisplayList

          posted @ 2008-03-28 09:58 oathleo 閱讀(492) | 評論 (0)編輯 收藏

          僅列出標題
          共17頁: First 上一頁 9 10 11 12 13 14 15 16 17 下一頁 
          主站蜘蛛池模板: 静乐县| 彭水| 江陵县| 朔州市| 麟游县| 武强县| 靖安县| 云林县| 靖边县| 蓝山县| 全州县| 赣州市| 阿巴嘎旗| 义马市| 漳州市| 湖口县| 通河县| 新绛县| 富蕴县| 内乡县| 千阳县| 浠水县| 延安市| 扶余县| 商洛市| 阿拉善左旗| 裕民县| 芮城县| 宁国市| 大足县| 江华| 高尔夫| 尉犁县| 阿坝| 普定县| 永昌县| 伊宁县| 茶陵县| 老河口市| 常熟市| 泗阳县|