TabNavigation in Flex


<?xml version="1.0"?>
<!-- Simple example to demonstrate the TabBar control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[

            import mx.events.ItemClickEvent;
            import mx.controls.TabBar;

            [Bindable]
            public var STATE_ARRAY:Array = [{label:"Alabama", data:"Montgomery"},
                {label:"Alaska", data:"Juneau"},
                {label:"Arkansas", data:"LittleRock"}
            ];
           
            private function clickEvt(event:ItemClickEvent):void {
                // Access target TabBar control.
                var targetComp:TabBar = TabBar(event.currentTarget);
                forClick.text="label is: " + event.label + ", index is: " +
                    event.index + ", capital is: " +
                    targetComp.dataProvider[event.index].data;
            }               
       ]]>
    </mx:Script>

    <mx:Panel title="TabBar Control Example" height="75%" width="75%"
        paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">

        <mx:Label width="100%" color="blue"
            text="Select a tab to change the current panel."/>

        <mx:TabBar itemClick="clickEvt(event);">
            <mx:dataProvider>{STATE_ARRAY}</mx:dataProvider>
        </mx:TabBar>

        <mx:TextArea id="forClick" height="100%" width="100%"/>

    </mx:Panel>
</mx:Application>

DataGrid Using Flex


<?xml version="1.0"?>
<!-- DataGrid control example. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:XMLList id="employees">
        <employee>
            <name>Christina Coenraets</name>
            <phone>555-219-2270</phone>
            <email>ccoenraets@fictitious.com</email>
            <active>true</active>
        </employee>
        <employee>
            <name>Joanne Wall</name>
            <phone>555-219-2012</phone>
            <email>jwall@fictitious.com</email>
            <active>true</active>
        </employee>
        <employee>
            <name>Maurice Smith</name>
            <phone>555-219-2012</phone>
            <email>maurice@fictitious.com</email>
            <active>false</active>
        </employee>
        <employee>
            <name>Mary Jones</name>
            <phone>555-219-2000</phone>
            <email>mjones@fictitious.com</email>
            <active>true</active>
        </employee>
    </mx:XMLList>

    <mx:Panel title="DataGrid Control Example" height="100%" width="100%"
        paddingTop="10" paddingLeft="10" paddingRight="10">

        <mx:Label width="100%" color="blue"
            text="Select a row in the DataGrid control."/>

        <mx:DataGrid id="dg" width="100%" height="100%" rowCount="5" dataProvider="{employees}">
            <mx:columns>
                <mx:DataGridColumn dataField="name" headerText="Name"/>
                <mx:DataGridColumn dataField="phone" headerText="Phone"/>
                <mx:DataGridColumn dataField="email" headerText="Email"/>
            </mx:columns>
        </mx:DataGrid>

        <mx:Form width="100%" height="100%">
            <mx:FormItem label="Name">
                <mx:Label text="{dg.selectedItem.name}"/>
            </mx:FormItem>
            <mx:FormItem label="Email">
                <mx:Label text="{dg.selectedItem.email}"/>
            </mx:FormItem>
            <mx:FormItem label="Phone">
                <mx:Label text="{dg.selectedItem.phone}"/>
            </mx:FormItem>
        </mx:Form>
       
    </mx:Panel>
</mx:Application>       

ComboBox using Flex


<?xml version="1.0"?>
<!-- Simple example to demonstrate the ComboBox control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            [Bindable]
            public var cards:ArrayCollection = new ArrayCollection(
                [ {label:"Visa", data:1},
                  {label:"MasterCard", data:2},
                  {label:"American Express", data:3} ]);
       
            private function closeHandler(event:Event):void {
                myLabel.text = "You selected: " +  ComboBox(event.target).selectedItem.label;
                myData.text = "Data: " +  ComboBox(event.target).selectedItem.data;
            }    
        ]]>
    </mx:Script>

    <mx:Panel title="ComboBox Control Example"
        height="75%" width="75%" layout="horizontal"
        paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">

        <mx:ComboBox dataProvider="{cards}" width="150"
            close="closeHandler(event);"/>

        <mx:VBox width="250">
            <mx:Text  width="200" color="blue" text="Select a type of credit card."/>
            <mx:Label id="myLabel" text="You selected:"/>
            <mx:Label id="myData" text="Data:"/>
        </mx:VBox>        

    </mx:Panel>   
</mx:Application>      

Create alert using Flex


<?xml version="1.0"?>
<!-- Simple example to demonstrate the Alert control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.CloseEvent;
       
            // Event handler function uses a static method to show
            // a pop-up window with the title, message, and requested buttons.       
            private function clickHandler(event:Event):void {
                Alert.show("Do you want to save your changes?", "Save Changes", 3, this, alertClickHandler);
            }
       
            // Event handler function for displaying the selected Alert button.
            private function alertClickHandler(event:CloseEvent):void {
                if (event.detail==Alert.YES)
                    status.text="You answered Yes";
                else
                    status.text="You answered No";
            }

            // Event handler function changes the default Button labels and sets the
            // Button widths. If you later use an Alert with the default Buttons,
            // you must reset these values.
            private function secondClickHandler(event:Event):void {
                Alert.buttonWidth = 100;
                Alert.yesLabel = "Magenta";
                Alert.noLabel = "Blue";
                Alert.cancelLabel = "Green";

                Alert.show("Select a color:","Color Selection",1|2|8,this);
               
                // Set the labels back to normal:
                Alert.yesLabel = "Yes";
                Alert.noLabel = "No";               
            }
        ]]>
    </mx:Script>

    <mx:Panel title="Alert Control Example" width="75%" horizontalAlign="center" paddingTop="10">
      <mx:Text width="100%" color="blue" textAlign="center"
          text="Click the button below to display a simple Alert window."/>
      <mx:Button label="Click Me" click="Alert.show('Hello World!', 'Message');"/>

      <mx:Text width="100%" color="blue" textAlign="center"
          text="Click the button below to display an Alert window and capture the button pressed by the user."/>
      <mx:Button label="Click Me" click="clickHandler(event);"/>
      <mx:Label id="status" fontWeight="bold"/>

      <mx:Text width="100%" color="blue" textAlign="center"
          text="Click the button below to display an Alert window that uses custom Button labels."/>
      <mx:Button label="Click Me" click="secondClickHandler(event);"/>
    </mx:Panel>

</mx:Application>

Hello World Flex Application


 <?xml version="1.0" encoding="utf-8"?>
<mx:application layout="absolute" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:panel height="200" layout="absolute" title="Hello World Application" width="250" x="140" y="42">
<mx:label fontsize="24" fontweight="bold" text="Hello World" x="22" y="28">
</mx:label>
</mx:panel>
</mx:application>

Starting Flex Application



Open Flex Builder 2/3 Click on File -> choose New ->Flex Project select "Flex Project" it prompt a New FlexProject window enter your project name in "Project name" field if you want to a specific location for project "browse" that folder,if not leave as default "Use default Location" in Project location box, select WebApplication in "Application type" at we are not going to add server so that leave as it is "Server tecchnology" box, then click on "Next" leave as bin-debug as output folder then click Next then it show two tabs Sourcepath and Librarypath. default Sourepath is highlihted if wish to Chage file name enter new name in "Main application file" field with extension .mxml ex: index.mxml . click on image to enlarge

Flex Examples

hi, Greetings of the Day for every one

My Sincere announcement for viewers , i would like post sample application on flex form November first Onwards,

Thanks for Visiting
Your Veluru

File Copy

import java.io.*
class CopyFile
{
int ch;
//reading data from args[0]
FileInputStream fin=new FileInputStream(args[0]);
// for writing data into args[1]
FileOutputStream fout=new FileOutPutStream(args[1]);
while(ch=fin.read()!=-1){
fout.write(ch);
}
fin.close();
fout.close();
}
}

Reading a File using FileReader

import java.io.*
class ReadFile
{
public static void Main(String[] args) throws IOException{
int ch;

// check if file exist or not
FileReader fr=null;
try{
fr= new FileReader("TestFile")
}catch(Exception e){
System.out.println("File Not Found");
return;
}
// read the file till end of the file
while(ch=fr.read()!=-1){
System.out.print((char)ch);
//close the file
fr.close();
}
}

Creating a File Using File Writer

import java.io.*
class CreateFile
{
public static void Main(String[] args) throws IOException{
String text="This is The File Content on Java" + "\n i am writing This in the
File";
// Attach a file to FileWriter
FileWriter fw=new FileWriter("TestFile");
// read the character wise from string and write into file
for(int i=0;i fw.write(text.charAt(i));
//close the file
fw.close();
}
}

To Save Image By Using Image

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/*
* @Author : Spice
* You Should give a File path to save
*/
public class SaveImage {
public static String stt;

public static void saveImage(File fileToSave )
{

// String stt=ImagePanel.pathname;
FileInputStream from = null;
FileOutputStream to = null;
try {
from = new FileInputStream(stt);
to = new FileOutputStream(fileToSave);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = from.read(buffer)) != -1)
to.write(buffer, 0, bytesRead);// write
to.close();
}catch(NullPointerException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
}

}

Reading XL Sheet By Using Java

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

/**
*
* @author spice
*/
public class MSPDetails {

final static String[] header = {"S.No", "Phone No", "Name", "Address"};

public static void main(String[] args) throws IOException, BiffException {
int option;
Workbook wb = Workbook.getWorkbook(new File("sample.xls"));
Sheet sheet1 = wb.getSheet(0);
Sheet sheet2 = wb.getSheet(1);
ArrayList notDisturbList=new ArrayList();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("############# MENU ################");
System.out.println("Select the criteria: \n 1 for name \n 2 for address \n 3 for quit");
System.out.println("Enter your option :");
option = Integer.parseInt(br.readLine());
System.out.println("########################################");
switch (option) {
case 1:
System.out.println("Enter employee Name:");
findByCriteria(sheet1, sheet2, "name", br.readLine());
break;
case 2:
System.out.println("Enter employee Address:");
findByCriteria(sheet1, sheet2, "address", br.readLine());
break;
case 3:
System.out.println("Thank Q");
break;
default:
System.out.println("Invalid choise..Enter correct choise");
}
} while (option != 3);

}

static void findByCriteria(Sheet sheet1, Sheet sheet2, String criteria, String key) throws IOException {
boolean isFound = true;
Cell nameCell = sheet1.findCell(criteria);
int nameCellNo = nameCell.getColumn();
Cell[] listName = sheet1.getColumn(nameCellNo);
Cell phno = sheet2.findCell("phone no");
int phnoCellNo = phno.getColumn();
Cell[] dontDisturbList = sheet2.getColumn(phnoCellNo);
int phColNo = sheet1.findCell("phno").getColumn();

System.out.println("PHONE NUMBER");
for (int row = 1; row < listName.length; row++) {
Cell[] rowCell = sheet1.getRow(row);

if (criteria.equals("name") ? listName[row].getContents().equals(key) : listName[row].getContents().contains(key)) {

// System.out.println(rowCell[phColNo].getContents());

for (int ddRow = 1; ddRow < dontDisturbList.length; ddRow++) {

if (rowCell[phColNo].getContents().equals(dontDisturbList[ddRow].getContents())) {

isFound = false;

System.out.println("This is Dont Disturb Number");
}
}
}
if (isFound) {

System.out.println(header[phColNo] + ":" + rowCell[phColNo].getContents());
}
}
if (!isFound) {
System.out.println("Details with " + criteria + " " + key + " doesn't exist");
}

}


}

Important Methods in String class

Here most common used String Methods Discussed Here


  • charAt() - Returns the Character located at at the specified index for Example :
    String x="Computer";
    System.out.println(x.charAt(2)); // output is 'm'

  • concat() - Appends one String to the end of another ("+" also works), ex:
    String x="motor";
    System.out.println(x.concat(" cab"));
    // output is "motor cab"

  • equalIgnoreCase() - Determines the equality of two Strings,ignoring case.
    String x = "HERO"
    System.out.println(x.equalIgnoreCase("Hero"));
       //is "true"
    System.out.println(x.equalIgnoreCase("reho"));    is "false"

  • length() - Returns the number of characters in a String.
    String x="Computer"
    System.out.println(x.length());     
    //     is 8

  • replace() - Replaces occurences of character with a new character

  • substring () - Returns a part of String
    String x = "0123456789"
    System.out.println(x.substring(5));     // output is "56789"
    System.out.println(x.substring(5,8));     //output is "567"

  • toLowerCase() - Returns a String with uppercase characters converted
    String x= "COMPUTERS";

    System.out.println(x.lowerCase());   //output is "computers"

  • toString() - returns the value of String
    String x = "Rama";
    System.out.println(x.toString());     // for your exercise buddy...

  • toUpperCase() - Returns a String with lowercase characters converted
    String x= "science";

    System.out.println(x.lowerCase());   //output is "SCIENCE"

  • trim() - Removes white spaces from ends of the String
    String x = " hi ";
    System.out.println(x + "x");    // result is " hi x"
    System.out.println(x.trim() + "x");    // result is " hix"

The String



In java String are objects.Just like other objects, we can create an instance of a String with the new Keyword ,as follows

String s=new String();

s="abcdef";
As you might expect, the String class has about a zillion constructors,so you can use a more efficient shortcut :

String s = new String("abcdef");

And just because you'll use strings all the time,you can even say this:

String s="abcdef";

Strings are immutable , means Once you have assigned a String value that value can never change. The good news
is that while the String object is immutable, its reference variable is not,
lets discussion start....

String s="abcdef";
// create a new string object ,with value "abcdef",refer s to it
String s2 = s;
// create a 2nd reference variable refferring to the same String

S = s.concat("more stuff");
// create a new String object, with value "abcdef more stuff", refer s to it
// change s's reference from the old String to the new String. ( R emember s2 is still referring
to the original "abcdef" String.)

The figure will give detailed explaination:

JAVA


  • Java is a programming language originally developed by "Sun Microsystems" and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler "object model" and fewer low-level facilities. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture.


  • The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun made available most of their Java technologies as free software under the GNU General Public License.Others have also developed alternative implementations of these Sun technologies.


  • The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun made available most of their Java technologies as free software under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies.


  • Sun released the first public implementation as Java 1.0 in 1995. It promised "Write Once, Run Anywhere" (WORA), providing no-cost run-times on popular platforms. Fairly secure and featuring configurable security, it allowed network- and file-access restrictions. Major web browsers soon incorporated the ability to run secure Java applets within web pages, and Java quickly became popular. With the advent of Java 2 (released initially as J2SE 1.2 in December 1998), new versions had multiple configurations built for different types of platforms. For example, J2EE targeted enterprise applications and the greatly stripped-down version J2ME for mobile applications. J2SE designated the Standard Edition. In 2006, for marketing purposes, Sun renamed new J2 versions as Java EE, Java ME, and Java SE, respectively.