咖啡伴侣

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

     摘要:   阅读全文

posted @ 2008-04-08 12:11 oathleo 阅读(2324) | 评论 (0)编辑 收藏

     摘要: Ext是一个非常好的Ajax框架,其华丽的外观表现确实令我们折服,然而一个应用始终离开不服务器端,因此在实现开发中我们需要对Ext与服务器端的交互技术有较为详细的了解,在开发中才能游刃有余地应用。本文对Ext应用中与服务器交互的常用方法作具体的介绍,本文的内容大部份来源于《ExtJS实用开发指南》。  总体来说,Ext与服务器端的交互应用可以归结为三种类型,包含表单FormPanel的处理(提交、...  阅读全文

posted @ 2008-04-07 11:00 oathleo 阅读(1576) | 评论 (1)编辑 收藏

     摘要:   阅读全文

posted @ 2008-03-28 10:11 oathleo 阅读(1711) | 评论 (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 阅读(594) | 评论 (0)编辑 收藏

     摘要:   阅读全文

posted @ 2008-03-28 10:08 oathleo 阅读(5917) | 评论 (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 阅读(538) | 评论 (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 阅读(352) | 评论 (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 阅读(436) | 评论 (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 阅读(472) | 评论 (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 阅读(484) | 评论 (0)编辑 收藏

仅列出标题
共17页: First 上一页 9 10 11 12 13 14 15 16 17 下一页