- Mã: Chọn tất cả
package Zstar;
/**
*
* @author zstar
*/
public class Point {
private int X = 0;
private int Y = 0;
public Point() {
}
public Point(int x, int y) {
this.X = x;
this.Y = y;
}
public int getX() {
return this.X;
}
public int getY() {
return this.Y;
}
}
Lớp LoadingScreen.java
- Mã: Chọn tất cả
package Zstar;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
/**
* @author ZSTAR
*/
public class LoadingScreen extends GameCanvas {
private Graphics g;
private String logo = "/Images/logo.png";
private String text1 = "Game tiếng việt trên điện thoại";
private String text2 = "Đang tải...";
private Image imageLogo;
private Point root = new Point(30, 50);
private Font fontNormal;
private Font fontBold;
//thanh loading
private int colorBorder = 0x000000;
private int colorLoading = 0xcc3301;
private int loadingLength = 150;
private int loadingHeight = 5;
private int loadingCurrent = 0;
private int h = 10;
private MainMidlet mainMidlet;
public LoadingScreen(MainMidlet main) {
super(false);
this.mainMidlet = main;
this.g = this.getGraphics();
this.fontNormal = g.getFont();
this.fontBold = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
setFullScreenMode(true);
try {
imageLogo = Image.createImage(logo);
} catch (IOException ex) {
ex.printStackTrace();
}
this.root = new Point(getWidth() / 2 - imageLogo.getWidth() / 2, root.getY());
}
public void start() {
clearScreen();
draw();
draw_next_loading();
}
public void draw() {
g.setColor(0x000000);
g.drawImage(imageLogo, root.getX(), root.getY(), Graphics.TOP | Graphics.LEFT);
g.drawString(text1, getWidth() / 2 - fontNormal.stringWidth(text1) / 2, root.getY() + imageLogo.getHeight(), Graphics.TOP | Graphics.LEFT);
g.setFont(fontBold);
g.drawString(text2, getWidth() / 2 - fontBold.stringWidth(text2) / 2, root.getY() + imageLogo.getHeight() + 40, Graphics.TOP | Graphics.LEFT);
g.setFont(fontNormal);
//draw loading
g.setColor(colorBorder);
g.drawRect(getWidth() / 2 - loadingLength / 2, root.getY() + imageLogo.getHeight() + 30, loadingLength, loadingHeight);
g.setColor(colorLoading);
g.fillRect(getWidth() / 2 - loadingLength / 2, root.getY() + imageLogo.getHeight() + 30, loadingCurrent, loadingHeight);
g.setColor(colorBorder);
this.flushGraphics();
}
private void draw_next_loading() {
clearLoading();
//timer.schedule(task, interval,interval);
for (int i = 0; i < loadingLength / h; i++) {
if (loadingCurrent < loadingLength) {
loadingCurrent += h;
//draw loading
g.setColor(colorBorder);
g.drawRect(getWidth() / 2 - loadingLength / 2, root.getY() + imageLogo.getHeight() + 30, loadingLength, loadingHeight);
g.setColor(colorLoading);
g.fillRect(getWidth() / 2 - loadingLength / 2, root.getY() + imageLogo.getHeight() + 30, loadingCurrent, loadingHeight);
g.setColor(colorBorder);
this.flushGraphics();
try {
Thread.sleep(100);
} catch (Exception e) {
}
} else {
loadingCurrent = 0;
break;
}
}
}
private void clearLoading() {
g.setColor(0xffffff);
g.fillRect(getWidth() / 2 - loadingLength / 2, root.getY() + imageLogo.getHeight() + 30, loadingLength, loadingHeight);
this.flushGraphics();
}
public void clearScreen() {
g.setColor(0xffffff); // white
g.fillRect(0, 0, getWidth(), getHeight());
this.flushGraphics();
}
}
tạo Lớp MainMidlet.java
- Mã: Chọn tất cả
package Zstar;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.*;
/**
* @author ZSTAR
*/
public class MainMidlet extends MIDlet {
private LoadingScreen loadingScreen;
public void startApp() {
loadingScreen=new LoadingScreen(this);
Display.getDisplay(this).setCurrent(loadingScreen);
loadingScreen.start();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}