You Are Here:

Community: Wiki

This page was last modified on 6 September 2009, at 17:30.

Barra de loading simples, usando Canvas, em Java ME

From Forum Nokia Wiki

Original em: Simple Canvas loading bar

Este é um exemplo de uma simples barra de 'loading' baseada no 'Canvas', você pode utiliza-la como uma 'splash screen' (tela de inicialização) para sua aplicação.

Primeiro criamos o 'Canvas' da aplicação e pegamos a largura (width) e a altura (height) da tela:

height = getHeight();
width = getWidth();

Em seguida preparamos um "fator" para a incrementação do 'loading':

factor = width / 4;

Também criamos um objeto Timer:

Timer timer = new Timer();

Este é o código que será usado no método 'paint' de nosso Canvas:

g.setColor(0x00ffccff);
g.fillRect(0, 0, width, height);
g.setColor(0x00ffffff);
g.fillRect(25, height / 2, width - 50, 2);
g.setColor(0x003399ff);
g.drawString("Application name", 100, (height / 2) - 30, Graphics.TOP | Graphics.HCENTER);
g.fillRect(25, height / 2, current, 2);
g.drawString("Loading...", 100, (height / 2) + 20, Graphics.BOTTOM | Graphics.HCENTER);

Em seguida criamos a classe que irá herdar/extender de TimerTask, dentro de nossa classe Canvas, para manipular a animação:

private class Draw extends TimerTask {
public void run() {
current = current + factor;
if (current > width - 50) {
current = 0;
repaint();
} else {
repaint();
}
}
}

No construtor do MIDlet, nós programamos o objeto 'timer' para ser ser executador:

repaint();
timer.schedule(new Draw(), 2000, 2000);

Precisamos criar agora um objeto do tipo Canvas, em nosso MIDlet, e exibir nossa barra de 'loading'.

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia