Splash Screen là 1 màn hình chờ mỗi khi chạy chương trình. Mục đích của Splash Screen rất đa dạng và tùy thuộc vào người viết/tạo ra chương trình đó. Ví dụ như chỉ là để hiện Logo của chương trình, 1 dòng Slogan hay Welcome ...Hay trong khi chương trình initialize thì ta cho hiện Splash Screen, khi initialize xong thì Splash Screen biến mất và giao diện chính của chương trình sẽ hiện ra... Đây là đoạn code tạo Splash Screen cơ bản dùng để hiện Logo của chương trình trong khoản 2 giây sẽ tự mất và display màn hình chính của chương trình. Khi chạy chương trình thì ra sẽ tạo SplashScreen trước và pass vào Screen cần display sau đó (là màn hình chính của chương trình) Code: /* * SplashScreen.java * * © tinhte.vn, 2010 * Confidential and proprietary. * * Developer: Keeper * Email: louis.keeper[MENTION=362321]Gmail.Com[/MENTION] */ package MyBrowser; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.system.*; import java.util.*; public class SplashScreen extends MainScreen { private MainScreen next; // Đây là màn hình chính của chương trình. Sau 1 khoản thời gian SplashScreen biến mất thì sẽ display next private UiApplication application; private Timer timer = new Timer(); private static final Bitmap _bitmap = Bitmap.getBitmapResource("logo.png"); // logo.png là file logo cần display. public SplashScreen(UiApplication ui, MainScreen next) { // Ta cần pass 2 param là Chương trình chính và màn hình chính cần display sau khi SplashScreen biến mất. super(Field.USE_ALL_HEIGHT | Field.FIELD_LEFT); this.application = ui; this.next = next; this.add(new BitmapField(_bitmap)); SplashScreenListener listener = new SplashScreenListener(this); this.addKeyListener(listener); timer.schedule(new CountDown(), 1500); // Time để SplashScreen tồn tại (đơn vị miliseconds) application.pushScreen(this); } public void dismiss() { timer.cancel(); application.popScreen(this); application.pushScreen(next); // Display next sau khi SplashScreen close. } private class CountDown extends TimerTask { public void run() { DismissThread dThread = new DismissThread(); application.invokeLater(dThread); } } private class DismissThread implements Runnable { public void run() { dismiss(); } } protected boolean navigationClick(int status, int time) { dismiss(); return true; } protected boolean navigationUnclick(int status, int time) { return false; } protected boolean navigationMovement(int dx, int dy, int status, int time) { return false; } public static class SplashScreenListener implements KeyListener { private SplashScreen screen; public boolean keyChar(char key, int status, int time) { //intercept the ESC and MENU key - exit the splash screen boolean retval = false; switch (key) { case Characters.CONTROL_MENU: case Characters.ESCAPE: screen.dismiss(); retval = true; break; } return retval; } public boolean keyDown(int keycode, int time) { return false; } public boolean keyRepeat(int keycode, int time) { return false; } public boolean keyStatus(int keycode, int time) { return false; } public boolean keyUp(int keycode, int time) { return false; } public SplashScreenListener(SplashScreen splash) { screen = splash; } } }
Đâu phải thay vào điện thoại . Đây là Splash Screen hiện lên trước khi vào màn hình chính của chương trình . Bác Keeper port nhiều code nữa nhé , em mới học Java và lập trình cho con BB của mình thấy còn bỡ ngỡ nhiều lắm , cần nhiều code để tham khảo chút . Thanks bác