Loading na aplicação

4 respostas
R

Ola galera!

eh o seguinte, quando eu faço uma ação que vai demandar tempo em resposta para o usuario, estou exibindo uma mini tela de aguarde, porem, estou tentando colocar uma figura gif animada.

So que quando executo uma dessas ações so aparece a tela sem o gif, apenas no fim do processamento da ação eh que o gif eh carregado.

Ja tentei usar thread com a maxima prioridade e nada.

Alguem ja passou por este mesmo problema que o meu?

4 Respostas

francislon

Jovem me mostre como vc fez isso que to tentando fazer isso aqui também e tá dando erro.
Se puder me mandar um email com o código eu agradeço.
[email removido]

L

porque não tenta carregar o gif antes de lançar a thread…!!!

lucamartins

Com a Thread deveria funcionar. Você verificou se chamou o metodo Thread.start() ?

R

Segue logo abaixo o codigo do Loading de minha aplicação:

package plano.compra.comunicacao;

import java.awt.Frame;
import java.awt.Dimension;
import java.awt.Window;
import java.awt.Rectangle;
import java.awt.Toolkit;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Color;
import java.awt.Label;
import java.awt.SystemColor;
import java.awt.Font;

public class PainelLoading extends Thread{
	
	private Frame frameLoading = null;  //  @jve:decl-index=0:visual-constraint="244,19"
	private Window windowLoading = null;
	private Label textoLoading = null;
	private JLabel textoGif = null;
	
	public void run(){
		getWindowLoading();		
	}
	
	public void destruir(){	
		frameLoading.setVisible(false);		
		frameLoading.addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowClosing(java.awt.event.WindowEvent e) {
				System.out.println("windowClosing()"); // TODO Auto-generated Event stub windowClosing()
			}
		});
		frameLoading = null;		
		windowLoading.setVisible(false);
		windowLoading.addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowClosing(java.awt.event.WindowEvent e) {
				System.out.println("windowClosing()"); // TODO Auto-generated Event stub windowClosing()
			}
		});
		windowLoading = null;
	}
	/**
	 * This method initializes frameLoading	
	 * 	
	 * @return java.awt.Frame	
	 */
	private Frame getFrameLoading() {
		if (frameLoading == null) {
									
			textoGif = new JLabel();
			textoGif.setBounds(new Rectangle(50, 114, 132, 30));
			textoGif.setIcon(new ImageIcon(getClass().getResource("/plano/compra/comunicacao/imagens/loading.gif")));
			textoGif.setText("");
			textoLoading = new Label();
			textoLoading.setBounds(new Rectangle(9, 44, 237, 80));
			textoLoading.setForeground(SystemColor.activeCaptionText);
			textoLoading.setFont(new Font("Comic Sans MS", Font.BOLD, 48));
			textoLoading.setText("Aguarde...");
			frameLoading = new Frame();
			frameLoading.setLayout(null);
			frameLoading.setSize(new Dimension(250, 150));
			frameLoading.setTitle("Aguarde...");
			frameLoading.setVisible(true);
			frameLoading.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/plano/compra/comunicacao/imagens/icon.jpg")));
			frameLoading.setBackground(new Color(51, 153, 0));
			frameLoading.setResizable(false);
			frameLoading.add(textoLoading, null);
			frameLoading.add(textoGif, null);
			frameLoading.addWindowListener(new java.awt.event.WindowAdapter() {
				public void windowClosing(java.awt.event.WindowEvent e) {
					System.out.println("windowClosing()"); // TODO Auto-generated Event stub windowClosing()
				}
			});
			frameLoading.setLocationRelativeTo(null);
		}
		return frameLoading;
	}
	/**
	 * This method initializes windowLoading	
	 * 	
	 * @return java.awt.Window	
	 */
	private Window getWindowLoading() {
		if (windowLoading == null) {
			windowLoading = new Window(getFrameLoading());
			windowLoading.setLocationRelativeTo(null);
			windowLoading.setVisible(true);
			windowLoading.addWindowListener(new java.awt.event.WindowAdapter() {
				public void windowClosing(java.awt.event.WindowEvent e) {
					System.out.println("windowClosing()"); // TODO Auto-generated Event stub windowClosing()
				}
			});
		}
		return windowLoading;
	}
}

Carregar o gif antes não tem como por que está no objeto.

Alguem tem outra sugestão?

Criado 9 de maio de 2008
Ultima resposta 9 de mai. de 2008
Respostas 4
Participantes 4