Monthly Archives: March 2011

How to make gear joint in Box2D, iPhone?

By | March 7, 2011

Gear joints are one of the real specialities of Box2D. By creating gear joints between two bodies you can actually simulate a real world gear. For creating a gear joint you need two bodies connected by a revolute or prismatic joint. The below code creates two bodies in the shape of a circle which is… Read More »

Swing JPanel with background image

By | March 7, 2011

This code add an image to Jpanel. JPanel panel1 = new JPanel(); JFrame recursion_frame = new JFrame(); BackgroundPanel stack_image1 = new BackgroundPanel(“Recursion.jpg”); panel1.setLayout(null); panel1.setLayout(new BorderLayout()); panel1.setBackground(Color.lightGray); panel1.setVisible(true); recursion_frame.setContentPane(panel1); ///adding to panel… recursion_frame.getContentPane().add(stack_image1); //adding image to panel…

Position swing window in center of the screen

By | March 7, 2011

In some case we need to position the window in the center of the screen . The same effect can be achieved by hard coding the center points .But in that case the window position change when the screen resolution changes This code will position the window in center irrespective of different screen resolutions public… Read More »

What is Objective C Keyword id ?

By | March 6, 2011

Hi, Objective C uses a special keyword ‘id’. Let’s see what it is. Objective C -id- is actually a ‘pointer to an object’. That is ‘id’ can hold a pointer to any objective c object. It doesn’t matter the object’s class. eg: NSString *myString = @”Coderz Heaven!”; id newString; NSString *tempString; newString=myString; tempString=newString; That’s it!… Read More »

Read a plist from your resources folder in Iphone Objective C

By | March 6, 2011

Plist or property list are usually used for storing data in iPhone. They are normal XML files, you can open it in a texteditor to view it’s data. This sample code shows how to read data from the plist. Reading a plist will return an array.You can print out the array to view the results.… Read More »

Remove unwanted memory from iPhone….

By | March 5, 2011

Hi all …… You know iPhone doesnot have garbage collection like ANDROID. So it becomes the responsibility of the developer or programmer to release the resources and remove the unwanted textures from your memory. If you don’t remove the unused textures and other variables from your memory your application will exit after a while. You… Read More »

Collision Detection In Box2D – Using With Cocos2D

By | March 5, 2011

For an interactive game building using Box2D, collision detection of Box2D bodies is necessary. There is an easy way to implement collision detection in Box2D. For checking whether two bodies have collided with each other in Box2D while using it with cocos2D, then use the following lines of code where ever you want to check… Read More »

Removing Unused Textures in Cocos2D

By | March 5, 2011

Sometimes unused textures may cause you memory leak! So you need to remove the unused textures. For removing unused textures, use the following line of code, where ever you want to remove unused textures. [[TextureMgr sharedTextureMgr] removeUnusedTextures]; 🙂

Removing Forces From Your World in Box2D Cocos2D

By | March 5, 2011

Hi, In certain situations you may need to remove all the forces you have applied on different bodies in your box2D world. Then what to do? Removing all the forces from the bodies in the box2D world is simple. Just use the single line of code. yourWorld->ClearForces(); Here yourWorld is your Box2D world. Simple, isn’t… Read More »

File Operations in Adobe AIR/FLEX

By | March 5, 2011

The following example shows how to deal with a simple text file in Adobe AIR/FLEX. This example illustratesd how to write a string to a text file and save it in the desktop. However you can use the “application directory” but make sure that you have necessary write permission to access the directory. Please leave… Read More »

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 »