Ah, madali lang yan. :) Meron akong nabasang book dati pa. Parang sa Sun ata na book yun. Anyway, eto po yun:
Name this as SplashScreen.java:
package com.pinoyjavatutorial.screens;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
public class SplashScreen extends Canvas {
private Display display;
private Displayable next;
private Timer timer = new Timer();
public SplashScreen(
Display display, Displayable next ){
this.display = display;
this.next = next;
display.setCurrent( this );
}
protected void keyPressed( int keyCode ){
dismiss();
}
protected void paint( Graphics g ){
g.setColor(0x000000);
g.drawString("Hello World from Pinoy Java Tutorial!", getWidth() / 2, getHeight() / 2, Graphics.HCENTER | Graphics.TOP);
}
protected void pointerPressed( int x, int y ){
dismiss();
}
protected void showNotify(){
timer.schedule( new CountDown(), 5000 );
}
private void dismiss(){
timer.cancel();
display.setCurrent( next );
}
private class CountDown extends TimerTask {
public void run(){
dismiss();
}
}
}
then to naman yung mismong main class: Main.java
package com.pinoyjavatutorial.main;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import com.pinoyjavatutorial.screens.SplashScreen;
public class Main extends MIDlet implements CommandListener {
private Display display;
private Command exit = new Command("Exit", Command.EXIT, 1);
protected void destroyApp(boolean bool)
throws MIDletStateChangeException {
exitMIDlet();
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
if (display == null) {
display = Display.getDisplay(this);
new SplashScreen(display, new FormTalaga());
}
}
public void exitMIDlet() {
notifyDestroyed();
}
public void commandAction(Command c, Displayable d) {
exitMIDlet();
}
class FormTalaga extends Form {
FormTalaga() {
super("FormTalaga");
addCommand(exit);
setCommandListener(Main.this);
}
}
}
Ang maganda po dito, pag pumindot kayo, mawawala na yung screen. Yung ibang approach kasi like while and for loops medyo minsan ayaw mawala nung splash screen pag pumindot ka na. Or kaya it tends to be inconsistent kasi based sya sa frequency ng processor ng device.
Food, Food, Food
11 years ago
No comments:
Post a Comment