Author Archives: admin

Creating a JMenubar in java swing

By | March 4, 2011

Creating a JMenubar is simple. JMenuBar menubar = new JMenuBar(); JMenu menu1 = new JMenu(“File”); JMenu menu2= new JMenu(“Help”); file = new JMenuItem(“Exit to menu”); edit = new JMenuItem(“Exit”); JMenuItem about = new JMenuItem(“About us”); f.setJMenuBar(menubar); menu1.add(file); menu1.add(edit); menu2.add(about); menubar.add(menu1); menubar.add(menu2); file.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { //Action…… } }); edit.addActionListener(new ActionListener() {… Read More »

How to load a PDF in Titanium?

By | March 3, 2011

Loading a PDF file in Titanium may be sometimes our requirement for an application. For loading a PDF we need to have a webview inside a scrollview so that it is scrollable also. Take a look at this simple example. /** creating a window **/ var window = Titanium.UI.createWindow{}; /** creating a webview **/ var… Read More »

Dynamically Load CSS in Adobe AIR/FLEX / Load css in Adobe AIR/FLEX using Class.

By | March 2, 2011

This example shows how to dynamically load css in Adobe AIR / FLEX. Here in this example Panel id the tag name for the panel control. Drag a panel control to your design then copy the code to your source file. “myTabs” is the class for the CSS. Panel { borderColor: #CBE0FF; border-style:solid; borderThickness: 1;… Read More »

Client Side Form Validation – using JavaScript

By | March 1, 2011

Hi, JavaScript is mainly used for client side scripting. In client side scripting one of the thing which we are usually in need is Validation of Forms. We want to know the user , who is interacting with the form have already given the necessary details before submitting or saving etc. Here is a simple… Read More »

Using ButtonBar in Adobe AIR/FLEX, A simple Example

By | March 1, 2011

Hello………. A button Bar is a convenient way to place your buttons in an application. It saves a lots of space in your application interface. Take a look at the following example which shows how to use the ButtonBar. An itemClickEvent is attached to each button in the ButtonBar. You can place as many buttons… Read More »

How to load a URL in Objective C or Cocoa in iPhone?/ Open Safari in Objective C

By | March 1, 2011

This code snippet helps you to open a webpage in Safari. Code uses openURL to load the webpage in the web browser. Write this function as an action to a button……… – ( IBAction ) loadWebPageInSafari : ( id ) sender { NSURL *my_URL = [NSURL URLWithString:[Your_URL stringValue]]; if ( [ [NSWorkspace sharedWorkspace] openURL :… Read More »

Using Arrays in JavaScript – Basics

By | February 28, 2011

Hi… We all know, Arrays are nothing but variables which can hold all your variable values with a single name. Let’s see some basic operations of Arrays in JavaScript. To Create a New Array. Use the following code. var myArray = new Array(); This code of line created a new Array object called myArray. Adding… Read More »

How to get a selected Item from a spinner in ANDROID?

By | February 28, 2011

We have come across this issue many times during programming to get a selected item in your combobox. ANDROID has built in functions to get the selected item from a spinner. Take a look at the snippet. Here my_spinner id the spinner variable and using getSelectedItem() which will return an object and by using toString()… Read More »

How to add more than One HTML Document in a single Browser ?

By | February 28, 2011

Hi… There may arise certain situations where you need to include more than one HTML document in the same browser. But how? It’s simple. It’s by using FRAMES of HTML. FRAMES can be included inside FRAMESET. Let’s see an example. <frameset cols="200,400"> <frame src="http://www.coderzheaven.com" /> <frame src="http://www.google.com" /> </frameset> This will create two column frames… Read More »

ProgressBar in ANDROID…..

By | February 28, 2011

Progress bars are our basic needs when we want to show something for a long time or some progress takes a long time and we want to show it’s progress. Keeping that in mind ANDROID also has built in progress views. There are basically two types of progress views in ANDROID. ProgressDialog.STYLE_SPINNER and ProgressDialog.STYLE_HORIZONTAL Take… Read More »

Toggle between Full Screen and normal Screen in Adobe AIR or FLEX.

By | February 27, 2011

Hi all……… We often need to toggle between fullscreen and normal screen in our application. The following code snippet helps you to toggle between these two screens in Adobe AIR or Flex. Here I am using StageDisplayState class to do both which has “stage.displayState = StageDisplayState.FULL_SCREEN” and ” stage.displayState = StageDisplayState.NORMAL” constants to do this.… Read More »

How to detect shake Gesture in your iPhone Cocos2D?

By | February 26, 2011

For detecting shake in a cocos2D program copy these lines to your layer class bool shaked_once; //default false self.isAccelerometerEnabled = YES; [[UIAccelerometer sharedAccelerometer] setUpdateInterval:1/60]; shaked_once = false; Then copy this function to the same file…. and you are done…….. -(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { float THRESHOLD = 2; if (acceleration.x > THRESHOLD || acceleration.x… Read More »

Hide and Show a Text Using jQuery – Example

By | February 26, 2011

With jQuery manipulation of HTML & CSS can be done very easily. Here we are going to show how to Hide a line of text using jQuery & Show it back also. Let’s code speak first…. <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#hideButton").click(function(){ $("p").hide(); }); $("#showButton").click(function(){ $("p").show(); }); }); </script> </head> <body> <p>Hey!… Read More »

Preventing Overriding in Java

By | February 25, 2011

Methods and variables can be ‘override’ in subclasses. (Yes, it’s a good feature too!). But what if we don’t want to ‘override’ our Methods and Variables in Java? It’s simple… Declare them using the keyword ‘final’ as modifier. That’s it. eg: final int myVariable = 79; So the value of myVariable can never be changed… Read More »

Creating Exceptions in JAVA

By | February 25, 2011

This is a simple custom exception in java. That is, we can create an exception by extending the exception class. The “throw new MyExcep” will throw an exception and the error message we specified will be displayed import java.lang.Exception; @SuppressWarnings(“serial”) class MyExcep extends Exception { MyExcep(String Errormsg) { super(Errormsg); // call Exception class error message… Read More »

How to use MediaPlayer in ANDROID? A simple example.

By | February 25, 2011

MediaPlayer class can be used to play Audio in ANDROID. See how to do this. MediaPlayer mp = new MediaPlayer(); mp = MediaPlayer.create(MyClassName.this,songId); try { mp.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (Exception e) { Toast.makeText(Switch.this,e.getMessage() , Toast.LENGTH_SHORT).show(); } mp.start(); //Called when the song completes….. mp.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer mp) {… Read More »

PHP- Warning: session_start(): Cannot sent session cache limiter-headers already sent, ERROR

By | February 24, 2011

Most of the beginners in PHP while using sessions at the first time might have encountered a long error, starting with something like, Warning:session_start(): Cannot sent session cache limiter- headers already sent Fix : It’s too simple! Don’t ever leave atleast a single space before the PHP code (starting with

How to check whether GPS is available in ANDROID or Not?

By | February 24, 2011

This code helps you to check whether the location service is available on your ANDROID Phone or not. Copy this code and paste to your file. Happy coding….. public boolean GPSAvailable() { LocationManager loc_manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<string> str = loc_manager.getProviders(true); if(str.size()>0) return true; else return false; }

String Functions in C

By | February 23, 2011

Let’s now briefly discuss about four essential String function used in C. We are going to discuss about a) strlen() b) strcpy() c) strcat() d) strcmp() Codes speak louder than words! Let’s see what these functions do in a simple C Program. #include main() { char stringOne[15] = “CoderzHeaven”; char stringTwo[] =”Codes”; char stringThree[15]; int… Read More »