Swing application for Windows CE and CrE-ME

This is same as Writing Applet Application. The Only thing we need to the followings

Step1:
Take the javax.swing package from http://www.nsicom.com/Default.aspx?tabid=295.

You will get a CAB file, put it on the PDA device and click on it to install. It will fire a dialog box. Select the root folder of the CrE-ME.

Step2:
The write a sample Swing program:

Bellow program also shows how to set a user defined icon left most of the Title bar.

import javax.swing.*;
import java.awt.*;

public class Sample
{

public static void main(String[] args)
{

JFrame frame = new JFrame("Setting an Icon for a frame");
frame.setIconImage(Toolkit.getDefaultToolkit().getImage("icon_confused.gif"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setVisible(true);
}
}

NB: keep your image icon in the same package where the program is.

Finally produce the jar file and keep it in the PDA and run it.

Java in Windows CE with CrE-ME

Developing CDC application with CrE-ME VM’s:
Recently I just worked with PDA devices and got to develop an application for that PDA which holding Windows CE Operating System. Let us know all that steps to be followed for this circumstance.

NB: For CDC devices there are two JV’s are well known which requires license to work. Both are

  • IBM J9
  • CrE-ME
CrE-ME can be used for a month of trial. IBM J9 does not give trial any more but earlier it used to.

Step 1:
Download Microsoft Active Sync from the bellow link, You may need to sign in to your MSN id to download

http://www.microsoft.com/windowsmobile/en-us/help/synchronize/activesync45.mspx

Step 2:
Install the Active Sync then connect the PDA and try to access the PDA device.

Step 3:
Download JVM CrE-ME 4.12 and CrEme 3.29 from http://nsicom.com/, free evaluation. And install both with having PDA connected to the PC . U will get confirmation in the PDA while installed

Step4:
Write your Applet and produce the .jar of it.
Here is my sample program

//MainTest.java
import java.applet.Applet;

import java.awt.*;

import java.awt.event.*;


public class MainTest extends Frame implements ComponentListener
{

private Label StepLabel ;

private MenuBar mbar;

private Menu menu;
private MenuItem mitem, msolve;

AboutGSL about;
NewForm newForm;


public void init ()
{

setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize());

setLayout (null);

about=new AboutGSL();
newForm=new NewForm();

mbar = new MenuBar();
menu = new Menu("File");
mbar.add(menu);

mitem = new MenuItem("New");

menu.add(mitem);

mitem = new MenuItem("Update");

menu.add(mitem);

msolve = new MenuItem("Delete");

menu.add(msolve);
mitem = new MenuItem("Exit");
menu.add(mitem);
menu = new Menu("Help");

mbar.setHelpMenu(menu);

mitem = new MenuItem("About");
menu.add(mitem);
setMenuBar(mbar);

show();

start();

}


public void start () {}

public void stop () {}

public MainTest (String s) { super(s);
}


public synchronized boolean handleEvent (Event event)
{

if (event.id == Event.ACTION_EVENT)
{

if ("About".equals (event.arg))

about.setVisible(true);
if ("New".equals (event.arg))

newForm.setVisible(true);
if ("Exit".equals (event.arg))

System.exit(0);
else{
}
}

else if (event.id == WindowEvent.WINDOW_CLOSING)

System.exit(0);

return true ;
}

public void componentResized(java.awt.event.ComponentEvent e)
{

if (e instanceof java.awt.event.WindowEvent)
{

setVisible(false);

stop();

init();
}

}

public void componentMoved(ComponentEvent e) {}
public void componentShown(ComponentEvent e) {}

public void componentHidden(ComponentEvent e) {}


public static void main(String args[]) {

MainTest app = new MainTest(" GSL Sample Application");
app.init();
app.addComponentListener(app);
}

}

//
NewForm.java
import java.awt.*;
import java.awt.event.*;

class NewForm extends Frame
{

Button save=new Button(" Save ");

Button OK = new Button (" Close ") ;

Label nameL = new Label ("Enter Name",Label.LEFT) ;

TextField nameT = new TextField (30) ;

Label fnameL = new Label ("\nEnter Father Name",Label.LEFT) ;
TextField fnameT = new TextField (30) ;
Label addL = new Label ("Enter Address") ;

TextField addT = new TextField (30) ;

Label contactL = new Label ("Enter Contact Number") ;

TextField contactT = new TextField (30) ;


public NewForm ()
{

super ("About Grameen Solutions") ;

setSize (Toolkit.getDefaultToolkit().getScreenSize().width/2, Toolkit.getDefaultToolkit().getScreenSize().height /2) ;
setResizable (false) ;

setLayout (new FlowLayout ()) ;

add(nameL);

add(nameT);

add(save);

add (OK) ;

}


public synchronized boolean handleEvent (Event event)
{

System.out.println( event);

if (event.id != Event.ACTION_EVENT)
{

if (event.id == WindowEvent.WINDOW_CLOSING)
{

dispose ();
return true;

}
else
return false ;
}

if (" Close ".equals (event.arg))

dispose () ;
return true ;

}

}


//
AboutGSL.java
import java.awt.* ;
import java.awt.event.* ;

class AboutGSL extends Frame
{

Button OK = new Button (" Close ") ;
Label Caption = new Label ("Passbook V1.0", Label.CENTER) ;

Label c1 = new Label ("developed for Sample Demo", Label.CENTER) ;

Label c2 = new Label (" ", Label.CENTER) ;

Label c3= new Label (" ", Label.CENTER) ;


public AboutGSL ()
{

super ("About Grameen Solutions") ;

setSize (Toolkit.getDefaultToolkit().getScreenSize().width/2, Toolkit.getDefaultToolkit().getScreenSize().height /4) ;

setResizable (false) ;

setLayout (new FlowLayout (FlowLayout.CENTER, 500, 0)) ;
add (c2);

add (c3);

add (Caption);

add (c1);

add (OK) ;

}

public synchronized boolean handleEvent (Event event)
{

System.out.println( event);

f (event.id != Event.ACTION_EVENT)
{

if (event.id == WindowEvent.WINDOW_CLOSING)
{

dispose ();

return true;

}
else
return false ;
}

if (" Close ".equals (event.arg))

dispose () ;
return true ;

}

}


Step5:
Put yor .jar file inside the
Windows\creme\demos\ directory of your PDA and try to run it by double clicking on it.

Its worked fine for me.