📄 welcomeui.java
字号:
/*
* WelcomeUI.java
*
* Created on 2006年3月22日, 上午9:24
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
package com.j2medev.sample.phonebook;
import javax.microedition.lcdui.*;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
/**
*
* @author Admin
*/
public class WelcomeUI extends Canvas{
private PhoneBookMidlet midlet = null;
// private Displayable nextUI = null;
private Image img = null;
private int width;
private int height;
private int y = 0;
private Timer timer = new Timer();
private Font font = null;
private boolean first = true;
private Displayable dis;
/** Creates a new instance of SplashCanvas */
public WelcomeUI(PhoneBookMidlet midlet,Displayable d) {
this.midlet = midlet;
this.dis = d;
width = this.getWidth();
height = this.getHeight();
font = Font.getDefaultFont();
try{
img = Image.createImage("/logo.png");
}catch(IOException e){
e.printStackTrace();
}
y = height/2 - img.getHeight()/2;
}
protected void paint(Graphics g){
if(first){
clearBackground(g);
first = false;
}
//设置裁减区域
g.setClip(0,y, width, 5);
//绘制图片
g.drawImage(img, width / 2, height/ 2, Graphics.HCENTER| Graphics.VCENTER);
//图片绘制完成后就绘画文本
if(y> (height+img.getHeight())/2){
g.drawString("正在读取用户登录信息!!", width/2, (height+img.getHeight())/2+font.getHeight(), Graphics.HCENTER|Graphics.TOP);
}
}
protected void showNotify(){
timer.schedule(new TimerTask(){
public void run() {
repaint();
//画完图片和文字后就进入下个UI
if(y > (height + img.getHeight())/ 2+3*font.getHeight()){
//休眠500ms
try{
Thread.sleep(500);
}catch(Exception ex){
ex.printStackTrace();
}
dismiss();
}
y = y + 5;
}
},0,50);
}
private void dismiss(){
timer.cancel();
synchronized(midlet){
midlet.notify();
}
//midlet.setCurrent(dis);
}
private void clearBackground(Graphics g){
int color = g.getColor();
g.setColor(0xffffff);
g.fillRect(0, 0, width, height);
g.setColor(color);
}
protected void keyPressed(int keyCode){
dismiss();
}
protected void pointerPressed(int x,int y){
dismiss();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -