Bom dia galera!!!
Bom sou muito leigo em java, mas estou iniciando e estou amando essa linguagem.
Gostaria de saber quem pode me ejudar, pois presciso chamar outra janela apos 10 segundos que a tela inicial estiver ativa.
Como Fazer?
Valeu galera
Bom dia galera!!!
Bom sou muito leigo em java, mas estou iniciando e estou amando essa linguagem.
Gostaria de saber quem pode me ejudar, pois presciso chamar outra janela apos 10 segundos que a tela inicial estiver ativa.
Como Fazer?
Valeu galera
estude sobre o método sleep da classe Thread…
Ou… faça uma gambiarra nojenta com o currentTimeMillis()… :?
	public void carregaTelaComDelay(long segundos) {
		long inicio = System.currentTimeMillis();
		// verificação:
		System.out.println(Calendar.getInstance().get(Calendar.SECOND));
		while (System.currentTimeMillis() < inicio + (segundos * 1000)){
			// nada...
		}
		// verificação:
		System.out.println(Calendar.getInstance().get(Calendar.SECOND));
	}
Éca… estude Thread… :lol:
Pode usar o seguinte:
        
public static final long TEMPO = (1000 * 3); //FAZ VERIFICAÇÃO A CADA 3 SEGUNDOS
//****INICIA A TAREFA ELE VERIFICA A CADA UM MINUTO****//
        System.out.println("Inicio");  
         Timer timer = null;  
         if (timer == null) {  
             timer = new Timer();  
             TimerTask tarefa = new TimerTask() {  
                 public void run() {  
                     try {  
                         //chamar metodo
                        new janela().show();
                     } catch (Exception e) {  
                         e.printStackTrace();  
                     }  
                 }  
             };  
             timer.scheduleAtFixedRate(tarefa, TEMPO, TEMPO);  
         }
[quote=viniciusgundim]Pode usar o seguinte:
[code]
public static final long TEMPO = (1000 * 3); //FAZ VERIFICAÇÃO A CADA 3 SEGUNDOS
//INICIA A TAREFA ELE VERIFICA A CADA UM MINUTO//
System.out.println(“Inicio”);
Timer timer = null;
if (timer == null) {
timer = new Timer();
TimerTask tarefa = new TimerTask() {
public void run() {
try {
//chamar metodo
System.out.println(“Teste Agendador”);
enviar_email();
                 } catch (Exception e) {  
                     e.printStackTrace();  
                 }  
             }  
         };  
         timer.scheduleAtFixedRate(tarefa, TEMPO, TEMPO);  
     }[/code][/quote]
É uma boa alternativa também… apenas para conhecimento, a classe TimerTask implementa a interface Runnable, assim como a classe Thread… por isso o funcionamento delas é muito parecido…
Entao galera não entendi muito bem. baixo segue o codigo da minha janela, aonde quando clico no botao ela chama a outra janela, mas queria fazer o seguinta assim que a tela ser executada apos 10 segundo dela ativa ela chamar a outra.
[code]import javax.swing.;
import java.awt.;
import java.awt.event.;
import java.io.;
import javax.swing.Timer;
public class Entra extends JFrame implements ActionListener {
private JButton tela;
private JPanel pn1,pn2;
private JLabel lb1,lb2;
private Timer t;
ImageIcon  busgrande= new ImageIcon("busgrande.png");
ImageIcon  ld = new ImageIcon("load.gif");
public Entra() {
	
	super("Empresa de transporte Intermunicipal");
	setSize(350,350);
	setDefaultCloseOperation(EXIT_ON_CLOSE);
	pn1=new JPanel (new GridLayout(1,1));
	pn2=new JPanel (new GridLayout(1,1));
	lb1= new JLabel(ld);
	    	
	tela =new JButton(busgrande);
	tela.addActionListener(this);
	tela.setBackground(Color.WHITE);
	
	pn1.add(tela);
	pn2.add(lb1);
	
	pn2.setBackground(Color.WHITE);
	getContentPane().add(pn1,BorderLayout.CENTER);
	getContentPane().add(pn2,BorderLayout.SOUTH);
	  	 
	show();
}
 public void actionPerformed (ActionEvent evento)
{
	if (evento.getSource()==tela)
	{
		
		Onibus o = new Onibus();
		setVisible(false);
	}
		
}
 
public static void main(String [] args)
{
	Entra E = new Entra();
}
}[/code]
Testa aiii:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.Timer;
public class Entra extends JFrame implements ActionListener {
public static final long TEMPO = (1000 * 10);
private JButton tela;  
private JPanel pn1,pn2;  
private JLabel lb1,lb2;  
private Timer t;  
ImageIcon  busgrande= new ImageIcon("busgrande.png");  
ImageIcon  ld = new ImageIcon("load.gif");  
public Entra() {  
initComponents();
         //****INICIA A TAREFA ELE VERIFICA A CADA UM MINUTO****//
System.out.println(“Inicio”);
Timer timer = null;
if (timer == null) {
timer = new Timer();
TimerTask tarefa = new TimerTask() {
public void run() {
try {
//chamar metodo
System.out.println(“Teste Agendador”);
           } catch (Exception e) {  
               e.printStackTrace();  
           }  
       }  
   };  
   timer.scheduleAtFixedRate(tarefa, TEMPO, TEMPO);  
}
    super("Empresa de transporte Intermunicipal");  
    setSize(350,350);  
    setDefaultCloseOperation(EXIT_ON_CLOSE);  
    pn1=new JPanel (new GridLayout(1,1));  
    pn2=new JPanel (new GridLayout(1,1));  
    lb1= new JLabel(ld);  
    tela =new JButton(busgrande);  
    tela.addActionListener(this);  
    tela.setBackground(Color.WHITE);  
    pn1.add(tela);  
    pn2.add(lb1);  
    pn2.setBackground(Color.WHITE);  
    getContentPane().add(pn1,BorderLayout.CENTER);  
    getContentPane().add(pn2,BorderLayout.SOUTH);  
    show();  
}  
 public void actionPerformed (ActionEvent evento)  
{  
    if (evento.getSource()==tela)  
    {  
        Onibus o = new Onibus();  
        setVisible(false);  
    }  
}  
public static void main(String [] args)  
{  
    Entra E = new Entra();  
}  
}
É só usar qualquer um dos exemplos, pode ser o meu mesmo, pra fins de teste… no final do código, voce chama seu método…
Exemplo:
[code]import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
public class Entra extends JFrame implements ActionListener {
private JButton tela;
private JPanel pn1, pn2;
private JLabel lb1, lb2;
private Timer t;
ImageIcon busgrande = new ImageIcon("busgrande.png");
ImageIcon ld = new ImageIcon("load.gif");
public Entra() {
	super("Empresa de transporte Intermunicipal");
	setSize(350, 350);
	setDefaultCloseOperation(EXIT_ON_CLOSE);
	pn1 = new JPanel(new GridLayout(1, 1));
	pn2 = new JPanel(new GridLayout(1, 1));
	lb1 = new JLabel(ld);
	tela = new JButton(busgrande);
	tela.addActionListener(this);
	tela.setBackground(Color.WHITE);
	pn1.add(tela);
	pn2.add(lb1);
	pn2.setBackground(Color.WHITE);
	getContentPane().add(pn1, BorderLayout.CENTER);
	getContentPane().add(pn2, BorderLayout.SOUTH);
	show();
}
public void actionPerformed(ActionEvent evento) {
	if (evento.getSource() == tela) {
		Onibus o = new Onibus();
		setVisible(false);
	}
}
public static void main(String[] args) {
	carregaTelaComDelay(10);
}
public static void carregaTelaComDelay(long segundos) {
	long inicio = System.currentTimeMillis();
	while (System.currentTimeMillis() < inicio + (segundos * 1000)) {
		// nada...
	}
	Entra E = new Entra();
}
}[/code]
Blz cara mas e o seguinte ela nao carrega a primeira pagina ele da o tempo e chama a segunda tela
Que primeira página? Só existe um frame aí…
Cara resolvi nao tinha criado uma label e por isso o erro vlw pessoal