Friday, September 9, 2011

ExtJS (2.2.1): xtype button listeners

{
    xtype:'button'
    ,text:'add'
    ,listeners:{                                        
        'click' : function(){alert("hi!!");
        }                                        
}   
Reference:
http://stackoverflow.com/questions/2372353/extjs-how-can-i-add-event-handlers-to-a-component-in-its-raw-object-form-xtype

ExtJS (2.2.1): Ext.Button absolute position

A Button is not an Ext.BoxComponent, so it cannot be positioned using x and y properties. So the problem can be solved by adding the button to a transparent panel with the same size as the button.


var MyPanel = new Ext.Panel({
            layout:'absolute',
            width:400,
            height:200,
            items:[{
                xtype:'textfield',
                width:150,
                x:0,
                y:0
            },{
                xtype:'combo',
                width:150,
                x:160,
                y:0
            },{
                xtype:'panel',
                y:25,
                x:0,
                items:[
                {
                    xtype:'button',
                    text:'Search'
                }]
            }]
});

Source:
http://www.sencha.com/forum/showthread.php?37012-Ext.Button-absolute-position-help

HTML:Great Canvas Tutorial

Thursday, September 8, 2011

Javascript: string replace

var myString = "thisisastring";
myString.replace("i", "e");

Reference:

Java: Iterate a String


java.text.CharacterIterator;
java.text.StringCharacterIterator;
CharacterIterator it = new StringCharacterIterator("abcd");

// Iterate over the characters in the forward direction
for (char ch=it.first(); ch != CharacterIterator.DONE; ch=it.next()) {
    // Use ch ...
}
Reference:
http://www.exampledepot.com/egs/java.text/StrIter.html

Wednesday, September 7, 2011

Javascript: currency format function


function formatCurrency(num) {
   num = num.toString().replace(/\$|\,/g,'');
   if(isNaN(num))
   num = "0";
   sign = (num == (num = Math.abs(num)));
   num = Math.floor(num*100+0.50000000001);
   cents = num%100;
   num = Math.floor(num/100).toString();
   if(cents<10)
   cents = "0" + cents;
   for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
   num = num.substring(0,num.length-(4*i+3))+','+
   num.substring(num.length-(4*i+3));
   return (((sign)?'':'-') + '$' + num + '.' + cents);
}


Source:
http://javascript.internet.com/forms/currency-format.html

Java: replace chars in String

/*
        Replaces all occurrences of given character with new one
        and returns new String object.
*/

String returnString = "test string to do some change";
returnString = returnString.replace( 'o', 'd' );

Source:
http://www.javadeveloper.co.in/java-example/java-string-replace-example.html
http://javarevisited.blogspot.com/2011/12/java-string-replace-example-tutorial.html
References:
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html