2009-12-16

How to open a ECM file

There is a free program called unecm.exe to open ECM files. Just drag and drop the ECM file on to the unecm.exe icon. Then it will decode the file. unecm is a application which is used to decompress the ECM files. Usually converting a 600MB file to a ECM file format will reduce about 100MB (i.e. the file will become 500MB size). Roughly, converting a normal files into ECM will reduce 16-17% of the actual size.

2009-12-07

CMOS checksum error – Defaults loaded

When the computer boots, if that error is displayed, that means there is a problem in your CMOS battery (A battery located on the motherboard to store the system date, system passwords etc.)

Warning! CPU has been changed or CPU Ratio…

Above warning is also displayed along with this error because the system boot exactly can’t identify where the wrong, actually is. You must press F1 key in order to continue, after that message is being displayed.

You can ensure whether the wrong is with the CMOS battery or not, by setting the date and time in Windows. If the date and time remain correct after you switch on the computer again, that means your CMOS battery is working properly. If the date and time is reset to the default date and time when you switch on the computer that means the CMOS battery is not working.

I think it’s a good idea to write another important fact about CMOS battery at the moment I’m talking about it. You can reset your system passwords by removing the CMOS battery and then replace it after a while.

If you feel the error is not with the CMOS battery, you can try to resolve that problem by updating BIOS.

2009-11-27

How to get a database backup from SQL server

Right click on the database and select Tasks –> Backup….

Untitled

  Then select the database from the list of   available databases and select the destination folder by clicking on the Add button. Following image demonstrates that…

 

 

 

 

 

 

 

 

Untitled1

2009-11-25

How to get a appSettings value in a web.config file

Lets assume the following line has put between the <appSettings></appSettings> node.

<add key="StartingDate" value="09-05-2008" />

Now say, we want to get the value of the “StartingDate” in our C#.net code. All you want to do is, include the following line where you want to get the value.

ConfigurationManager.AppSettings["StartingDate"].ToString()

From the above line of code, you can get the “09-05-2008” value in your .net code.

Note: First of all you have to import the System.Configuration using the following code.

using System.Configuration;

2009-11-20

How to make the asp:HyperLink underlined and bold after clicked.

In C#.net code, call the asp:HyperLink controller by the id and apply the style as shown below.

name_of_the_controller.Style.Add("text-decoration", "underline");
name_of_the_controller.Style.Add("font-weight", "bold");

2009-11-19

How to set the alignment and font of the data in a column in asp:GridView

In the design view, click on the arrow shown in the top left corner of the asp:GridView component to get the GridView Tasks and then select ‘Edit columns…’. Then click on the minus sign of the ItemStyle to expand the properties. Then do the changes as shown below.

screen

2009-11-09

Method to erase the text from set of labels/textboxes at one glance in an iPhone application.

-(void)resetLabels{

Label1.text = @””;

Labe2.text = @””;

………………………….

}

If you want to erase the text from set of textboxes, do the same thing replaces the labels with text boxes. ;) Then call the method where appropriate. :)

How to move rows in a table in an iPhone application

Override the following delegate method to allow row moving.

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{

return YES;

}

-(void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath{

NSUInteger rowFrom = [fromIndexPath row];

NSUInteger rowTo = [toIndexPath row];

id idObject = [[array objectAtIndex: rowFrom] retain];

[array removeObjectAtIndex: rowFrom];

[array insertObject: idObject atIndex: rowTo];

[idObject release];

}

Override the above delegate method to do the actual row moving.

How to delete a row from a table in an iPhone application

Override the following delegate method as follows.

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

NSUInteger rowNumber = [indexPath row];

[self.array removeObjectAtIndex: rowNumber];

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

}

How to add an additional button to the navigation bar in an iPhone application

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"Additional" style:UIBarButtonItemStyleBordered target:self action:@selector(additionalAction:)];

self.navigationItem.rightBarButtonItem = barButton;

[barButton release];

How to initiate an NSDictionary type of object with the contents of a plist

NSString *pathForplist = [[NSBundle mainBundle] pathForResource:@"Objects" ofType:@"plist"];

NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile: pathForplist];

In my example, the plist file name is ‘Objects’.

How to play sound in an iPhone application

In the header file you must import the ‘AudioToolbox.h’ file in order to application to support for sounds. Add the following line of code in the top of the header file to import it.

#import <AudioToolbox/AudioToolbox.h>

Add the following line of codes inside the @interface in the header file.

SystemSoundID systemSoundID;

NSString *soundFilePath;

Then generate the getter and setter methods by adding the following line of code to the bottom of header file

@property (nonatomic, retain) NSString * soundFilePath;

and including the following line of code in the top of the .m file.

@synthesize soundFilePath;

Then import the sound file into your resources folder. In my example I imported an mp4 type file called ‘ruchira.mp4’.

Find the path to the sound file by adding the following code.

soundFilePath = [[NSBundle mainBundle] pathForResource:@"ruchira" ofType:@"mp4"];

Then create the system sound id for our sound file by adding the following code.

AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundFilePath], & systemSoundID);

Then add the following line of code where you actually want to play that sound. For example, if you want to play the sound when a button taps, and then includes the following code in the button action method.

AudioServicesPlaySystemSound(systemSoundID);

How to add an action sheet to an iPhone application

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose either one option" delegate:self cancelButtonTitle:@"I don’t need that" destructiveButtonTitle:@"I want to go there" otherButtonTitles:nil];

[actionSheet showInView:self.view];

[actionSheet release];

Action sheets come to handy when the application wants to prompt the user with options and user should not continue without selecting one option.

How to check the iPhone/iPod is camera supported or not from the application

All iPhone versions up to now are implicitly camera supported. But when we are writing iPhone apps, those can be run in iPhones as well as iPods. iPod don’t have a camera, so we have to check in the application, whether the application is deployed in an iPhone or in an iPod. Rather than doing that, we can check whether the device is camera supported or not by adding the following line of code.

[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]

We can also check whether the device support for a Photo Library or not by following line of code.

[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]

How to allow landscape orientation in an iPhone application

Override the shouldAutorotateToInterfaceOrientation method in the particular view class file, as follows

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);

}

Now the view is supported for landscape orientation.

2009-11-06

How to change the selected page number color in asp:GridView

Add the following lines in to css file.

.pager span 
{
    color:#000000;
    font-family: "Trebuchet MS";
    font-size: 14px;
    line-height: 20px;
}

Note: You can change the styles accordingly.

Add the following line in between <asp:GridView></asp:GridView> tags.

<PagerStyle BackColor="#EBEBEB" BorderColor="#EBEBEB" BorderStyle="Solid"
                        HorizontalAlign="Right" CssClass="pager" ForeColor="#0049B2" />

Fore color is the default color for page numbers other than the selected page.

2009-11-05

How to prevent the web browser from caching a web page

Include the lines shown below between the <head> </head> tags in the HTML page.

Ex:-

<head>

<meta http-equiv="Expires" CONTENT="0">

<meta http-equiv="Cache-Control" CONTENT="no-cache">

<meta http-equiv="Pragma" CONTENT="no-cache">

</head>

How to compare two databases in separate SQL servers and generate the SQL scripts

image

I have used a software called :”AdeptSQL Diff” to compare two databases from different SQL servers. It shows the tables, stored procedures, functions and other items one by one very clearly. From this software it is easy to compare the two databases and get to know what are the items available in one database and what are the items not available. We can also generate the scripts to make the two databases same by tables/stored procedures/functions/users. It is a very good software to even do modifications and run the scripts from there. From that software we can easily make the two databases same.

2009-10-26

How to initiate a phone call when the user taps on a phone number on an iPhone application

Declare the number with prefix “tel:”

NSString *tele = @"tel:0094-776764360";

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:tele]];

[tele release];

Proper way to add a text to the table cell in an iPhone application

First declare a label with x, y locations and width, height.

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 40, 110, 25)];

Then declare the text alignment, font and other properties in the text label.

label.textAlignment = UITextAlignmentLeft;

label.font = [UIFont boldSystemFontOfSize:14];

Finally set the text in label and add the label to the table cell as a sub view.

label.text = @"Address:";

[cell.contentView addSubview:label];

[label release];

2009-10-05

How to create a sequence of images animated in an iPhone application.

    NSArray *myImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"test.png"], [UIImage imageNamed:@"buddha.jpg"], nil];
    UIImageView *myAnimatedView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [myAnimatedView initWithFrame:[self.view bounds]];
    myAnimatedView.animationImages = myImages;
    myAnimatedView.animationDuration = 0.25; // seconds
    myAnimatedView.animationRepeatCount = 0; // 0 = loops forever
    [myAnimatedView startAnimating];
    [self.view addSubview:myAnimatedView];
    [myAnimatedView release];

2009-09-21

Age of Mythology Vs Age of Empires

Age of Mythology is about mythical creatures, ancient Greek gods and heroes. Age of Empires is based on ancient real world wars and warriors. Altogether there are 32 stages in Age of Mythology default campaign. Age of empires campaigns has lot of stages divided in many parts. Age of Mythology campaign is flow as a one story and the game player get the feeling, that he/she is also a character of the game story. Age of Empires has three versions, Age of Empires I (The rise of Rome), Age of Empires II and Age of Empires III. Now there is Age of Empires 4 too. Age of Empires has historical real world characters such as Archimedes, Julius Caesar, Alexander and Vercingetorix. Age of Mythology has mythical creatures, heroes and known Greek gods such as Zeus, Poseidon, Osiris and Ra.

Age of Mythology has a beautiful story behind the game. Age of Empires also has games which are based on real world incidents.

Both games demonstrate different cultures in different nations and countries. The graphic designers of both games have given a much priority to cloths of the characters, Building structures and the environment. Both games are excellent strategic games which were designed by Microsoft. I think, both game developing teams were consist around 150 persons. After successfully completing the games the credits are shown. Both games give the feeling of being in the game to the user.

There are expansion packs for both games. Expansion pack for Age of Mythology is “Age of Mythology – The Titans”. Age of Mythology –Titans is consist with base games which were available in Age of Mythology and there are extra campaigns for Titans. We can also download many different campaigns and scenarios for the both games. Game users are free to design their own scenarios using scenario builder provided with the game. But there is no guarantee that the downloaded campaigns and scenarios will be interesting as the original scenarios.

To play Age of Mythology, high performance computer is needed relative to Age of Empires. Graphics is high quality and more advance in Age of Mythology. It demonstrate God powers and other mythical features in an excellent manner.

There is no Age of Mythology II. The Age of Mythology Titans Expansion is considering as the 2nd version of Age of Mythology. But it is actually continued from the where Age of Mythology finished. In Age of Mythology Titans expansion, the Titans campaigns are starting from the where Age of Mythology ends. But the main role in Age of Mythology, Hero Arkantos, is not there. He is dead and the main role in Age of Mythology Titans expansion is his son. In Titans expansion, Arkantos is acting as a god but can’t use in the game. Al together there are 12 stages in Titans expansion campaigns. In last few stages, there are different Titans and we have to deal with them using different strategies. In the last stage (12th stage) only we can have a Titan in our own. Following video shows how our titan (Gaia) fight with the enemy titan (Kronos) and end the Age of Mythology Titans expansion.

Kronos is the son of Gaia and he is the king of all Titans. It’s said that Greek gods are children of Titans. But the power of Olympians is the fact that keep the Titans imprisoned.

It’s actually very nice game flowing like a movie.

When talking about Age of Mythology and Age of Empires, we can’t forget about the sounds and music. There are high quality sounds provided in both games. Music composers have done a great job in here.

In Age of Mythology there are three kinds of gods to follow. Those are Greek, Egyptian and Norse. In the titans expansion, we can worship to Titans and at the end we can build a Titan gate and release a Titan. In Age of Empires, there are different different Ages to advance through. Like wise in Age of Mythology, we have to worship gods/titans to advance through. According to the God or Titan we choose to worship, the powers and technology will be having. There are 9 major gods including, Zeus, Hades, Thor, Loki, Ra, Set. Age of Mythology is a game based on the way the humans were used in the war between Underworld and Olympus.

 

In the Titans Expansion, it’s really hard to play, if we set the difficulty mode to Titan. The computer will advanced very quickly by gathering resources immediately. Then it will release the Titan in a short period of time and Titan will come to our base to attack. So the game will be over after the computer release the Titan. Titan is accompanied by a huge army. So, there is no way to attack them back without using cheats.

2009-09-16

What is the best Chat?

Nowadays, Chat is a very popular medium of communicating. These days it’s becoming very popular among professionals to communicate even officially. Some IT companies are conducting their interviews through video and voice chat.

When it comes to smileys, the yahoo messenger provides the best Emoticons. Here is the descending order of quality of smileys

Yahoo messenger > Google Talk, Skype > Facebook

Among the Chats mentioned above, facebook chat is the worst. Google Talk has very simple and user friendly GUI and Google talk is very reliable. Facebook chat is not reliable and poor with smileys. Yahoo messenger 10 is enriched with high quality animating smileys.

In Skype, if you have contacts from different countries other than your country, you can view their times.

2009-09-15

How to shift a given context in an iPhone application

CGContextTranslateCTM(context, 50, -350);

Code to shift the given context is shown above. First parameter is the context which wanted to shift. Second parameter is the value you want to shift the context along the x-axis and third parameter is the value you want to shift the context along the y-axis.

How to rotate a Context in an iPhone application

CGContextRotateCTM(context, radians(90));

Code to rotate a context is shown above. Give the context as the 1st parameter and give the degrees to the radians method. radians method is shown below.

static inline double radians (double degrees) {return degrees * M_PI/180;}

(Note: you may need to import math.h to use M_PI constant)

Add a timer in an iPhone application

Here is the code to add a timer object to an iPhone application

NSTimer *timer=[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(startTimer) userInfo:NULL repeats:YES];   

scheduledTimerWithTimeInterval – This is the time interval for timer to call a method

selector – This is the method which runs after the interval

repeats – If the user wants continuously run the particular method after the interval, this must be assigned as YES. Otherwise this will be NO.

How to view .mkv files in low performance computers

Open the VLC media player. Then click Tools –> Preferences. Then select Input & Codecs. Set the default caching level to Higher latency and Post-Processing quality to 999999999. Finally save the changes. Optionally you can also set the power setting on the computer to high performance for best results. Now you can view the .mkv files without chopping.

Create a Chat server in Java RPC

Create the .x file as follows and save it as msg.x


struct overdata{
int a;
String b;
};
program Chat {
version Chat_V1 {
String get(int)=2;
String get1(void)=4;
void chat(overdata)=3;
} = 1;
} = 1234567;


Create the client code as follows and save it as NewJFrame.java


import netbula.ORPC.*;
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
strart();
strart1();
}
@SuppressWarnings("unchecked")
//
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jButton3 = new javax.swing.JButton();
jToggleButton1 = new javax.swing.JToggleButton();
jLabel4 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Chat System");
setAlwaysOnTop(true);
setBackground(new java.awt.Color(0, 0, 0));
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jButton1.setText("Send");
jButton1.setToolTipText("Send Message");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setText("Client Number");
jButton2.setText("Receive");
jButton2.setToolTipText("Receive Messages");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel3.setText("Client Number");
jButton3.setForeground(new java.awt.Color(255, 0, 0));
jButton3.setText("Exit");
jButton3.setToolTipText("Exit the Chat System");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jToggleButton1.setForeground(new java.awt.Color(0, 0, 255));
jToggleButton1.setText("Enable polling");
jToggleButton1.setToolTipText("Push for enable");
jToggleButton1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(), javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)));
jToggleButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton1ActionPerformed(evt);
}
});
jLabel4.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
jLabel4.setForeground(new java.awt.Color(51, 51, 51));
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(65, 65, 65)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(79, 79, 79))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
.addComponent(jToggleButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(70, 70, 70)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(72, 72, 72))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(194, 194, 194))))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jToggleButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}//
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
Chat_cln cl = new Chat_cln("localhost", "udp");
Integer i=Integer.parseInt(jTextField1.getText());
String message=jTextArea1.getText();
overdata od=new overdata();
od.a=i;
od.b=message;
cl.chat(od);
System.out.println("Sent message");
}catch (rpc_err e) {
System.out.println("rpc: " + e.getMessage());
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
Chat_cln cl = new Chat_cln("localhost", "udp");
Integer i=Integer.parseInt(jTextField2.getText());
System.out.println(" Got message ");
String all=cl.get(i);
jLabel2.setText(all);
}catch (rpc_err e) {
System.out.println("rpc: " + e.getMessage());
}
}
//polling mechanism
private class Poll extends Thread{
public void run(){
while(true){
//get the remote object from the registry
try {
Chat_cln cl = new Chat_cln("localhost", "udp");
String all=cl.get1();
jLabel2.setText(all);
}catch (rpc_err e) {
System.out.println("rpc: " + e.getMessage());
}
}
}
}
Poll p=new Poll();
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(jToggleButton1.isSelected()){
p=new Poll();
jLabel4.setText("Polling enables");
p.start();
}
else{
jLabel4.setText("Polling disabled");
p.stop();
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
private class Animate extends Thread{
public void run(){
String str=new String();
str="Exit";
for(;;){
for(int i=0; i<=str.length();i++){ jButton3.setText(str.substring(0, i)); try { Animate.sleep(200); } catch (InterruptedException ex) { } if(i==str.length()){ try { Animate.sleep(2000); } catch (InterruptedException ex) { } } } } } } private class Animate1 extends Thread{ public void run(){ String str=new String(); str="CHAT SYSTEM - CREATED BY RUCHIRA CHANAKA"; for(;;){ for(int i=0; i<=str.length();i++){ setTitle(str.substring(0, i)); try { Animate1.sleep(200); } catch (InterruptedException ex) { } if(i==str.length()){ try { Animate1.sleep(2000); } catch (InterruptedException ex) { } } } } } } private void strart1(){ Animate1 a=new Animate1(); a.start(); } private void strart(){ Animate a=new Animate(); a.start(); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JToggleButton jToggleButton1; // End of variables declaration }
Create the Server code as follows and save it as Chat_server.java
import netbula.ORPC.*;
import java.util.*;
class Chat_server extends Chat_svcb {
//implement the server function,
//let's just echo the msg back
static HashMap messages=new HashMap();
//chat code
public void chat(overdata od){
Integer a=od.a;
String msg=od.b;
boolean flag = false;
if(!messages.isEmpty()){
Integer numbers[] = new Integer[messages.size()];
messages.keySet().toArray(numbers);
for(int i=0;i al=new ArrayList();
al.add(msg);
messages.put(a, al);
}
}
//get code
public String get(int a){
Integer numbers[] = new Integer[messages.size()];
messages.keySet().toArray(numbers);
boolean flag = false;
for(int i=0;i" all="">
flag=true;
while(b.hasNext()){
all_messages=(String) b.next();
all+=(all_messages+"
");
}
return ""+all;
}
}
if(!flag){
return "There are no messages from Client "+a;
}
return "test";
}
//method used for polling
public String get1(){
Set s=messages.keySet();
Iterator use=s.iterator();
String all="";
while(use.hasNext()){
ArrayList temp;
int temp_no=(Integer)use.next();
temp=messages.get((Integer)temp_no);
String all_messages="";
if(temp!=null){
Iterator b=temp.iterator();
String final_messages="Message to Client "+temp_no+": ";
while(b.hasNext()){
all_messages=final_messages+(String) b.next();
all+=(all_messages+"
");
}
}
}
return all;
}
//main function runs the server
public static void main(String srgv[]) {
//let's run the server using the run() method in Svc
//For more flexibility, one could use the TCPServer and UDPServer directly
try {
new Chat_server().run();
} catch (Exception e) {
System.out.println("a major problem");
}
}
}</NUMBERS.LENGTH;I++){></NUMBERS.LENGTH;I++){></INTEGER,></INTEGER,>

  • Open the Command Prompt
  • Change directory to the current working directory (RPC)
  • Compile the msg.x file
    • “jrpcgen msg.x”

  • Compile the client code ·
    • “javac –cp .;lib/orpc.jar NewJFrame.java”
  • Compile the server code ·
    • “javac –cp .;lib/orpc.jar Chat_server.java”
  • Compile the port mapper code ·
    • “javac –cp .;lib/orpc.jar pmapsvc.java”
  • Run the port mapper ·
    • “java –cp .;lib/orpc.jar pmapsvc”

clip_image002[13]

  • Run the server
    • “java –cp .;lib/orpc.jar Chat_server”

clip_image002[15]

  • Run the client
    • “java –cp .;lib/orpc.jar NewJFrame”

image

image

Create a Chat server in Java RMI

Create the Interface class as follows and name it as Inter.java

import java.rmi.*;

public interface Inter extends Remote
{
  public void chat(Integer a,String b) throws RemoteException;
  public String get(Integer a) throws RemoteException;
  public String get() throws RemoteException;
}

Create the Server class as follows and name it as Chat_server.java

import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;

public class Chat_server extends UnicastRemoteObject implements Inter{

    static HashMap<Integer, ArrayList> messages=new HashMap<Integer, ArrayList>();

    Chat_server() throws RemoteException{
        super();
    }

    public void chat(Integer a, String msg) throws RemoteException{

        boolean flag = false;

    if(!messages.isEmpty()){
    Integer numbers[] = new Integer[messages.size()];
    messages.keySet().toArray(numbers);

    for(int i=0;i<numbers.length;i++){

        if(a.intValue()==numbers[i].intValue()){
        ArrayList temp;
        temp=messages.get(a);
        temp.add(msg);
        messages.put(a, temp);
        flag=true;
        }

    }

    }

    if(!flag){
            ArrayList<String> al=new ArrayList<String>();
            al.add(msg);
            messages.put(a, al);
    }

    }

    public String get(Integer a) throws RemoteException{

        Integer numbers[] = new Integer[messages.size()];
        messages.keySet().toArray(numbers);
        boolean flag = false;

    for(int i=0;i<numbers.length;i++){

        if(a.intValue()==numbers[i].intValue()){
        ArrayList temp;
            temp=messages.get(a);
            Iterator b=temp.iterator();
            String all_messages="<html>", all="";
            flag=true;

            while(b.hasNext()){
                all_messages=(String) b.next();
                all+=(all_messages+"<br>");
            }

            return "<html>"+all;

        }

    }

        if(!flag){
            return "There are no messages from Client "+a;
        }

        return "test";

    }
   
    //method used for polling
   
    public String get() throws RemoteException{

        Set s=messages.keySet();
        Iterator use=s.iterator();
        String all="";

    while(use.hasNext()){

        ArrayList temp;
        int temp_no=(Integer)use.next();
            temp=messages.get((Integer)temp_no);
            String all_messages="";

            if(temp!=null){
            Iterator b=temp.iterator();
            String final_messages="<html><I><tt>Message to Client "+temp_no+": </tt></I>";

            while(b.hasNext()){
                all_messages=final_messages+(String) b.next();
                all+=(all_messages+"<br>");
            }

            }
           
    }

    return all;

    }

    public static void main(String args[]){

        try{
        System.setSecurityManager(new RMISecurityManager());
        //set the security manager

        //create a local instance of the object
        Chat_server server = new Chat_server();

        //put the local instance in the registry
        Naming.rebind("CHAT-SERVER" , server);

        System.out.println("Server waiting.....");
        }

        catch (java.net.MalformedURLException me){
        System.out.println("Malformed URL: " + me.toString());
        }

        catch (RemoteException re){
        System.out.println("Remote exception: " + re.toString());
        }

    }

}

Create the Client class as follows and name it as NewJFrame.java

import java.rmi.*;
import java.rmi.server.*;

public class NewJFrame extends javax.swing.JFrame {

    public NewJFrame() {
        initComponents();
        strart();
        strart1();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jToggleButton1 = new javax.swing.JToggleButton();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Chat System");
        setAlwaysOnTop(true);
        setBackground(new java.awt.Color(0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jButton1.setText("Send");
        jButton1.setToolTipText("Send Message");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setText("Client Number");

        jButton2.setText("Receive");
        jButton2.setToolTipText("Receive Messages");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel3.setText("Client Number");

        jButton3.setForeground(new java.awt.Color(255, 0, 0));
        jButton3.setText("Exit");
        jButton3.setToolTipText("Exit the Chat System");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jToggleButton1.setForeground(new java.awt.Color(0, 0, 255));
        jToggleButton1.setText("Enable polling");
        jToggleButton1.setToolTipText("Push for enable");
        jToggleButton1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(), javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)));
        jToggleButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(51, 51, 51));
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(65, 65, 65)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(79, 79, 79))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                            .addComponent(jToggleButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(70, 70, 70)
                                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(72, 72, 72))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(194, 194, 194))))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToggleButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
       
            // set the security manager for the client
            System.setSecurityManager(new RMISecurityManager());
     
            //get the remote object from the registry
            try{
            System.out.println("Security Manager loaded");
            String url = "//localhost/CHAT-SERVER";
            Inter remoteObject = (Inter)Naming.lookup(url);
            System.out.println("Got remote object");
            Integer i=Integer.parseInt(jTextField1.getText());
            String message=jTextArea1.getText();
            remoteObject.chat(i, message);
            System.out.println(" Sent message ");
            }
           
            catch (RemoteException exc){
            System.out.println("Error in lookup: " + exc.toString());
            }
       
            catch (java.net.MalformedURLException exc){
            System.out.println("Malformed URL: " + exc.toString());  
            }
       
            catch (java.rmi.NotBoundException exc){
            System.out.println("NotBound: " + exc.toString());
            }
       
    }
   
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
       
            // set the security manager for the client
            System.setSecurityManager(new RMISecurityManager());
     
            //get the remote object from the registry
            try{
            System.out.println("Security Manager loaded");
            String url = "//localhost/CHAT-SERVER";
            Inter remoteObject = (Inter)Naming.lookup(url);
            System.out.println("Got remote object");
            Integer i=Integer.parseInt(jTextField2.getText());
            System.out.println(" Got message ");
            String all=remoteObject.get(i);
            jLabel2.setText(all);
            }
           
            catch (RemoteException exc){
            System.out.println("Error in lookup: " + exc.toString());
            }
       
            catch (java.net.MalformedURLException exc){
            System.out.println("Malformed URL: " + exc.toString());  
            }
       
            catch (java.rmi.NotBoundException exc){
            System.out.println("NotBound: " + exc.toString());
            }
    }
   
    //polling mechanism
   
    private class Poll extends Thread{
   
        public void run(){
       
        while(true){
            // set the security manager for the client
            System.setSecurityManager(new RMISecurityManager());
     
            //get the remote object from the registry
            try{
            System.out.println("Security Manager loaded");
            String url = "//localhost/CHAT-SERVER";
            Inter remoteObject = (Inter)Naming.lookup(url);
            System.out.println(" Got message ");
            String all=remoteObject.get();
            jLabel2.setText(all);
            Poll.sleep(10000);
            }
           
            catch (RemoteException exc){
            System.out.println("Error in lookup: " + exc.toString());
            }
       
            catch (java.net.MalformedURLException exc){
            System.out.println("Malformed URL: " + exc.toString());  
            }
       
            catch (java.rmi.NotBoundException exc){
            System.out.println("NotBound: " + exc.toString());
            }
           
            catch (InterruptedException ex) {
            }
           
        }
       
        }
   
    }
   
    Poll p=new Poll();
   
    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        if(jToggleButton1.isSelected()){
            p=new Poll();
            jLabel4.setText("Polling enables");
            p.start();
        }
        else{
            jLabel4.setText("Polling disabled");
                p.stop();
        }
    }
   
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        System.exit(0);
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame().setVisible(true);
            }
        });
    }
   
    private class Animate extends Thread{

        public void run(){
            String str=new String();
            str="Exit";

            for(;;){
                    for(int i=0; i<=str.length();i++){
                     jButton3.setText(str.substring(0, i));
                try {
                    Animate.sleep(200);
                } catch (InterruptedException ex) {
                }
                if(i==str.length()){
                try {
                    Animate.sleep(2000);
                } catch (InterruptedException ex) {
                }
                }
                    }
            }

        }

    }
   
        private class Animate1 extends Thread{

        public void run(){
            String str=new String();
            str="CHAT SYSTEM - CREATED BY RUCHIRA CHANAKA";

            for(;;){
                    for(int i=0; i<=str.length();i++){
                     setTitle(str.substring(0, i));
                try {
                    Animate1.sleep(200);
                } catch (InterruptedException ex) {
                }
                if(i==str.length()){
                try {
                    Animate1.sleep(2000);
                } catch (InterruptedException ex) {
                }
                }
                    }
            }

        }

    }
   
    private void strart1(){
    Animate1 a=new Animate1();
    a.start();
    }

    private void strart(){
    Animate a=new Animate();
    a.start();
    }

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JToggleButton jToggleButton1;
    // End of variables declaration

}

Open the Command Prompt

  • Change directory to the current working directory (RMI)
  • Compile the interface class
    • “javac Inter.java”
  • Compile the Server class
    • “javac Chat_server.java”
  • Generate the stub
    • “rmic Chat_server”
  • Compile the Client class
    • “javac NewJFrame.java”
  • Start the RMI registry
    • “start rmiregistry”
  • Start the server
    • “java -Djava.security.policy=policy.all Chat_server” 
    clip_image002

  • Start the Client
    • “java -Djava.security.policy=policy.all NewJFrame”


image image 


    2009-09-14

    How to create a splash screen in J2ME

    import java.io.IOException;
    import javax.microedition.lcdui.*;

    public class MIDPCanvas extends Canvas implements CommandListener {

    public MIDPCanvas() {
    try {
    // Set up this canvas to listen to command events
    setCommandListener(this);
    // Add the Exit command
    addCommand(new Command("Exit", Command.EXIT, 1));
    } catch(Exception e) {
    e.printStackTrace();
    }
    }

    /**
    * paint
    */
    public void paint(Graphics g) {
    //Set the screen to Fullscreen
    setFullScreenMode(true);
    g.setColor(0x00FFFFFF);
    g.fillRect(0, 0, getWidth(), getHeight());
    Image img=null;
    try {
    //Set the picture
    img = Image.createImage("/picture/Untitled-1.png");
    } catch (IOException ex) {
    ex.printStackTrace();
    }
    g.drawImage(img, getWidth() / 2, getHeight() / 2 - 5, 3);
    try{
    //Set the loading time here. I set it as 1 second (1000 milliseconds)
    Thread.sleep(1000);
    }
    catch(Exception e){
    System.out.println("Error");
    }
    }

    /**
    * Called when a key is pressed.
    */
    protected void keyPressed(int keyCode) {
    }

    /**
    * Called when a key is released.
    */
    protected void keyReleased(int keyCode) {
    }

    /**
    * Called when a key is repeated (held down).
    */
    protected void keyRepeated(int keyCode) {
    }

    /**
    * Called when the pointer is dragged.
    */
    protected void pointerDragged(int x, int y) {
    }

    /**
    * Called when the pointer is pressed.
    */
    protected void pointerPressed(int x, int y) {
    }

    /**
    * Called when the pointer is released.
    */
    protected void pointerReleased(int x, int y) {
    }

    /**
    * Called when action should be handled
    */
    public void commandAction(Command command, Displayable displayable) {
    }

    }

    How to create a password field in J2ME

     // Password field length is set to 9 and the label of the password text field is "Password:"
    private TextField passwd=new TextField("Password:", "", 9, TextField.PASSWORD);

    Code snippet to add images to Lists in J2ME


    try { 
     // Load the images to Image arrays

     image=new Image[]{Image.createImage("/picture/image1.png"), Image.createImage("/picture/image2.png"), Image.createImage("/picture/image3.png")};

     image2=new Image[]{Image.createImage("/picture/search_server.PNG"), Image.createImage("/picture/Calendar.png")};
    }

    catch (IOException ex) {
     ex.printStackTrace(); 
    }

    //Multiple choice Selection
    cri=new List("Select Search Method", List.MULTIPLE, search, image);

    //Implicit Selection
    menu=new List("Select:", List.IMPLICIT, choices, image2);