Thursday, July 1, 2010

Split string using delimiters

private String[] split(String original, String separator) {
    Vector nodes = new Vector();
    int index = original.indexOf(separator);
    while(index>=0) {
        nodes.addElement( original.substring(0, index) );
        original = original.substring(index+separator.length());
        index = original.indexOf(separator);
    }
    nodes.addElement( original );
    String[] result = new String[ nodes.size() ];
    if( nodes.size()>0 ) {
        for(int loop=0; loop
        result[loop] = (String)nodes.elementAt(loop);
    }
    return result;
}
    String ss=  "couples will randomly; appear " +
                "at several locations; across " +
                "the game screen.The; jumping " +
                "car will need to bump; into " +
                "these evil car; manifestations " +
                "using LEFT; or RIGHT keys to " +
                "defeatthem!; The more couples " +
                "that are; hit by the car in a" +
                "fixed; time the higher the score.;";

String[] result = split(ss, ";");
for(int i=0; i
        g.drawString(result[i],getWidth()>> 1,y,g.HCENTER | g.TOP);
        System.out.println(result[i]);
      
}

Friday, May 21, 2010

What is j2me..?


In J2ME, the Java runtime environment is adapted for constrained devices - devices that have limitations on what they can do when compared to standard desktop or server computers. For low-end devices, the constraints are fairly obvious: extremely limited memory, small screen sizes, alternative input methods, and slow processors. High-end devices have few, if any, of these constraints, but they can still benefit from the optimized environments and new programming interfaces that J2ME defines.

Learning about J2ME is not hard: Once you understand the new terminology, it's mostly about learning new APIs (application programming interfaces) and learning how to work in constrained environments. (If you think writing an applet is challenging, wait until you try to fit an application into the 30K of memory some cellphones provide!) You can use most of the same tools you already use in your code development, and with careful coding you can develop libraries of classes that are portable to any device or computer with a Java virtual machine.