Problemas com swing.Timer

0 respostas
F
Ola usuários do GUJ, :D Estou com um problema no meu código, gostaria que vocês me ajudassem. Eu fiz uma Splash screen que aparece durante 5 segundos daih abre uma JFrame(teste1). Ateh aih ok. E na JFrame tem um botão, que quando você clica, abre outra janela(teste2). OK tbm. Mas logo após, depois de 5 segundos novamente, aquela JFrame(teste1), aparece novamente. Eu acho que isso está ligado ao javax.swing.Timer que configurei para a splash. Então gostaria de saber como eu faço para parar isso, nao abrir mais a JFrame(teste1). Vou postar o código para facilitar:
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;


public class Principal extends JFrame{
	
	JButton  ok;
	
	public Principal(){
			super("Teste...");
			Container tela = getContentPane();
			tela.setLayout(null);
                                                ok = new JButton("Entrar");
                                                ok.setBounds(100,235,100,20);
                                                tela.add(ok);
                                                ok.addActionListener(
		                new ActionListener(){
		public void actionPerformed(ActionEvent e){
													if(oitava.isSelected() == true){
							TelaInicial2 tela2;
							tela2 = new TelaInicial2();
							tela2.setDefaultCloseOperation(EXIT_ON_CLOSE);
							tela2.setVisible(true);
							dispose();
							}
	}});
public static void main(String args[]){
			Principal app = new Principal();
			app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	}
		public void principal(){
			setVisible(true);}
		private class TelaInicial extends JWindow{
			public TelaInicial(){
				Container tela = getContentPane();
				tela.setLayout(new FlowLayout(FlowLayout.LEFT,1,1));
				ImageIcon imagem = new ImageIcon("imagens/splash.gif");
				JLabel rotulo = new JLabel(imagem);
				tela.add(rotulo);
				ActionListener fechar = new ActionListener(){
					public void actionPerformed(ActionEvent e){
						setVisible(false);
						dispose();
						principal();}};
			javax.swing.Timer timer = new javax.swing.Timer(5000,fechar);
			timer.start();
			pack();
			setLocationRelativeTo(null);
			
			}
		}

}
Criado 2 de agosto de 2007
Respostas 0
Participantes 1