Jūs esateŽurnalai / Ernestas Kardzys's blog / Howto. Show slash screen in JavaME
Howto. Show slash screen in JavaME
I was trying to create a splash screen in JavaME. And here it is:
[code lang="java"]
package info.ernestas.guicomponents;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
/**
* @author Ernestas Kardzys
*/
public class SplashScreen extends Canvas implements Runnable {
private Display display;
private Displayable next;
private long splashTime = 0;
private Thread thread;
public SplashScreen(Display display, Displayable next) {
this.display = display;
this.next = next;
this.display.setCurrent(this);
}
public SplashScreen(Display display, Displayable next, long splashTime) {
this.display = display;
this.next = next;
this.splashTime = splashTime;
this.display.setCurrent(this);
}
protected void paint(Graphics g) {
int width = getWidth();
int height = getHeight();
// Set background color
g.setColor(0x006000);
g.fillRect(0, 0, width, height);
Font font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_LARGE);
g.setColor(0x555555);
g.setFont(font);
g.drawString("Hello, World!", width/2, height/2, 0);
}
// Closes the screen
private void dismiss(){
if (isShown())
display.setCurrent(next);
}
public void showSplash() {
thread = new Thread(this);
thread.start();
}
public synchronized void notifyDone() {
notify();
}
public void keyReleased(int keyCode) {
// Do something if a key was pressed or dismiss(); ...
}
public void pointerReleased(int x, int y) {
// ... or with pointer - dismiss();
}
public synchronized void run() {
try {
// Splash time set - splash until time ends
if (splashTime > 0) {
Thread.sleep(splashTime);
}
else {
// No time set - wait until notified
wait();
}
dismiss();
}
catch (InterruptedException ex) {
ex.printStackTrace();
dismiss();
}
}
}
[/code]
You can call it like that:
[code lang="java"]
SplashScreen splashScreen = new SplashScreen(Display.getDisplay(this), new Form("New form!"), 2000);
splashScreen.showSplash(); // Show splash screen for 2 seconds (1 second = 1000 milliseconds)
[/code]
Or if you prefer to manually close the form:
[code lang="java"]
SplashScreen splashScreen = new SplashScreen(Display.getDisplay(this), new Form("New form!"));
splashScreen.showSplash();
// Some code here...
splashScreen.notifyDone();
[/code]


Šiuo atveju čia tiktai ekranas - nelabai ką ir parodysi :/
Kurioje nors savo programoje įtrauksiu :)
Sorry ne source o kompiliuota :)
O "source" tai turi omeny .JAVA failą?
Na... Čia per daug nėra ką vaizduoti :/ Toks žalias langas ir viskas :/
Ir vėl be source ir screen :)
Skelbti naują komentarą