部落格

Happy Chinese New Year for Everyone Here!!!

Hi, everyone who visits my site today, happy chinese new year!
Today is chinese New Year's Eve, And tomorrow is chinese Pig Year~~
Pig in Germany means lucky, in China also means prosperity and happiness.

And I wish you  and your family, your lover will be happy, peace and health in the new year!!!!

yours
leelight
2007.02.17

Touch J2ME Polish--5. First Application, begin with Loading Splash Screen

If you have used some J2ME applicaitons, e.g. some games, almost all of them will give you one loading splash screen when you start the game, or before you enter the next stage the waiting splash screen will tell you the progress of data loading. The standard solution is to provide a splash screen and do the necessary initialization in a background thread. And if you have done this before, your code will look like this:

//firstly difine one class to draw the logo and string on canvas
    public class SplashCanvas extends Canvas {
    
        protected void paint(Graphics g){
            try {
                icon_start=Image.createImage("/welcome.png");
            } catch (java.io.IOException e) {
                icon_start=null;
                System.out.println("Load image error when initializing Exception happens:" + e.getMessage());
            }
            g.drawImage(icon_start,getWidth()/2, getHeight()/2-15, Graphics.BOTTOM| Graphics.HCENTER);
           
            g.drawString("EasyWMS 1.00", getWidth()/2, getHeight()/2, Graphics.BOTTOM| Graphics.HCENTER );
            g.drawString("Loading...", getWidth()/2, getHeight()/2+15, Graphics.BOTTOM| Graphics.HCENTER );
            splashIsShown=true;
           
        }
        protected Graphics clearScreen(Graphics g) {
              // clear screen
              g.setColor(255, 255, 255);
              g.drawRect(0, 0, this.getWidth(), this.getHeight());
              return g;
             }
       
    }

//will run the splash screen in one background thread, for the further calling
   public class SplashScreen implements Runnable{
        private SplashCanvas splashCanvas;
       
        public void run(){
            splashCanvas = new SplashCanvas ();     
            display.setCurrent(splashCanvas);
            splashCanvas.repaint();
            splashCanvas.serviceRepaints();
            while(!isInitialized){
                try{
                    Thread.yield();
                }catch(Exception e){}
            }
        }     
    }  

//impletement this class as one thread, like this:
//public class genisMIDlet extends MIDlet implements Runnable{
//then give the run method
    public void run(){
        while(!splashIsShown){
            Thread.yield();
        }      
        doTimeConsumingInit();      
        while(true){
            // soft loop          
            Thread.yield();
        }
    }
   
//the splash will keep on displaying 3 seconds and then go to the main form automatically
    private void doTimeConsumingInit(){
        // Just mimic some lengthy initialization for 3 secs
        long endTime= System.currentTimeMillis()+3000;
        while(System.currentTimeMillis()<endTime ){}

        controller=new UIController(this);
        controller.init();
        isInitialized=true;
    }

//at last,  open 2 threads when initialize the application
    protected void startApp() throws MIDletStateChangeException {
        Thread splashthread= new Thread(new genisMIDlet.SplashScreen());
        splashthread.start();

     //now you can also load the data from database or something.....
        Thread thisThread = new Thread(this);
        thisThread.start();
    }

And if there are others progress need to give the user one waiting screen, those code will be write again with differnt string and image. Are you tired? Yes, I am tired of this.Polish provides the de.enough.polish.ui.splash.InitializerSplashScreen for this task. The splash screen shows an image along with an optional string message and initialize the actual application in a backgroud thread.  This is the code example:

package de.enough.polish.sample.splashScreen;

import java.io.IOException;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
import de.enough.polish.ui.splash.InitializerSplashScreen;
import de.enough.polish.ui.splash.ApplicationInitializer;;

public class SplashScreenDemo extends MIDlet
//#if !polish.clases.ApplicationInitializer:defined
    implements ApplicationInitializer
//#endif
{
    private Screen mainScreen;
    private Display display;
   
    protected void startApp() throws MIDletStateChangeException {
        this.display = Display.getDisplay(this);
        if(this.mainScreen !=null){
            //the MIDlet has been paused;
            this.display.setCurrent(this.mainScreen);
        }else{
              //the MIDlet is started for this first time
              try{
                  Image image = Image.createImage("/welcome.png");
                  int backgroundColor = 0xFFFFFF;
                  String readyMessage = "Press any key to continue...";
                  //Set readyMessage = null to forward to the next
                  //displayabe as soon as it's available
                  int messageColor = 0xFF0000;
                  InitializerSplashScreen splashScreen = new InitializerSplashScreen(this.display
                  ,image, backgroundColor, readyMessage,messageColor,this);
                  this.display.setCurrent(splashScreen);
              }catch(IOException e){
                throw new MIDletStateChangeException("Unable to load splash image");
              }
        }
    }

    public Displayable initApp(){
        //initialize the application.e.g. read data from record store,etc
        //.......
        //now create the main menu screen:
        //e.g. this.mainScreen = new Form("Main Form");

        this.mainScreen = new Form("Main Form");

        return this.mainScreen;

    }
   
    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // TODO Auto-generated method stub
       
    }

    protected void pauseApp() {
        // TODO Auto-generated method stub
       
    }
}
Splash Loading Screen:

Go to the main Form:

Have you seen that, only one function could do everything, creates a new InitializerSplashScreen using the internal default view.
public InitializerSplashScreen(Display display, Image image, int backgroundColor, java.lang.String readyMessage, int messageColor, ApplicationInitializer initializer)The message will be shown in the default font.Parameters:

Touch J2ME Polish--4. Test with Polish Example

If you selected install the polish example when you install the polish, now you can find about 10 examples in samples folder in your polish root folder. You havnt found? I have told you before, please update your harddisk to a big one~
Those examples are very very valuable for the polish beginners, including me. They are the basic interface of Polish UI and some simple application to help you create your own project.

Before the testing of these example, I record one error I have met today, maybe it is useful for you.

Touch J2ME Polish--3. Debug and Build with Ant

At first you should pay attenion to the source folder, if you have converted one existing project to Polish project. Polish's default source directoty is source/src, and default resource directory is resources. Please go to the project's properties and change the Java Build Path setting like this. Otherwise you can not build it successfully.

Now you can debug or build the project with Ant.

GIS Developing Follow Me with PHP--How to input CSV file with WKT into MySQL

If you have one CSV file that containing the WKT format SQL spatial data, how to input the data into MySQL?
For testing, at first create a table containing spatial colomn:

CREATE TABLE `geometry` (
`id` int( 11 ),
`geom` GEOMETRY ,
PRIMARY KEY ( `id` )
) TYPE = MYISAM;

In MySQL's operation software, Admin or PHPMyAdmin, you could run such SQL code to input the data:

"INSERT INTO geometry (id, geom) VALUES ('1', GeomFromText('LINESTRING(1283074 10562093,1283074 10562093,1283074 10562093)'));

svg2svgtconverter, one small interesting tool for converting SVG to SVGT

Yesterday I downloaded the Nokia S60 Platform SDKs for Symbian OS( for Java), from Nokia offical website. The version is 3rd edition, the newest SDK for developping J2ME. After the installation, I found one directory named S60Tools in the toolkit and there is one install file inside.
That is svg2svgtconverter.exe, you can easily know what kind of this software is from its name. Of course I installed it for testing,  only 1.85 Mb.

Touch J2ME Polish--2. Create Projects or Convert Existing Projects

After the installation of Polish, we can create Polish Project NOW~~

Create New J2ME Projects


1. Open File->New->Project, find the J2ME Plish Project in Java directory. (Why not in J2ME directory?) A funny chelonian, lol



2. Enter a project name, and click Generate Template if you like, it will create a MIDlet template in a package you named.

Error retrieving feature.xml in Eclipse--Using Software Updates and then Find and install

If you are using Eclispe, maybe you will meet such error after you have installed a Eclipse plugin:
Error retrieving "feature.xml". [error in opening zip file]
When you open Help->Software Updates->Find and install to install a new plugin, this error will cause that you can not install the new one. What is the problem?
Do you remember how did you install the last Eclipse plugin? I guess you download the package and unzip or just put it into Eclipse's directory, without using the Software Updates tool in Help menu in Eclipse.

Touch J2ME Polish--1. Installation

It is not required to introduce the famous J2ME Polish, the open source tools for creating "polished" wireless Java applications. J2ME Polish is best known for its ability to build and the  user interface, but  its inviting point is more than this. If you are a J2ME developper, I can bet that have found the reality is not like what sun has said:"Write once, run anywhere", but "Write once, debug anywhere", and you have tried of and hated to debug your applications on so many different devices, even they have only a little bit differences, you must modify hundreds of code. You can try J2ME Polish, maybe it can help you to solve those boring problems.

70 Popular Ajax Applications' Demo and Source Code

  1. Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell
  2. AJAX - microlink pattern tutorial : A microlink is a link that opens up content below it.
  3. Ajax BBC News RSS Reader : demo by Nigel Crawley
  4. AJAX Chat in Python with Dojo : at AquaAjax
  5. Ajax Chess : multiplayer chess
RSS feed