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
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:
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.
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.
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)'));
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.
最新回應
1 年 1 週 前
1 年 1 週 前
1 年 1 週 前
1 年 1 週 前
1 年 1 週 前
1 年 1 週 前
1 年 1 週 前
1 年 1 週 前
1 年 1 週 前
1 年 1 週 前