Fórum Temporizador #567506
09/02/2011
0
Ana Maruchi
Curtir tópico
+ 0Posts
09/02/2011
Alexandre Viriato
Gostei + 0
09/02/2011
Ana Maruchi
Gostei + 0
09/02/2011
Alexandre Viriato
Gostei + 0
09/02/2011
0
Ana Maruchi
Curtir tópico
+ 0Posts
09/02/2011
Alexandre Viriato
Gostei + 0
09/02/2011
Ana Maruchi
Gostei + 0
09/02/2011
Alexandre Viriato
Gostei + 0
09/02/2011
Javaxxx
class Teste
{
public static void main( String[] args ) throws InterruptedException
{
System.out.println( "ok" );
Thread.sleep( 5 * 1000 ); // aguarda 5segundos
System.out.println( "ok" );
Thread.sleep( 10 * 1000 ); // aguarda 10segundos
System.out.println( "ok" );
}
}
Gostei + 0
14/02/2011
Ana Maruchi
package p;
public class ClasseC extends javax.swing.JFrame {
public Saques() {
initComponents();
Thread.sleep( 10 * 1000 ); // dá erro,
}}
package p;
public Class Main{
public static void main( String[] args ) throws InterruptedException
{
CalsseA a = new ClasseA();
a.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
a.(true);System.out.println( "ok" );
Thread.sleep( 10 * 1000 ); // aguarda 10 segundos
ClasseB b = new ClasseB();// HÁ UM MÉTODO QUE CHAMA ClasseC
b.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
b.setVisible(true);
a.setVisible(false);
}
} Gostei + 0
14/02/2011
Javaxxx
...
public static void main( String[] args )
{
metodo();
}
// Aqui o método trata a possível exceção
private static void metodo()
{
try
{
System.out.println( "ok" );
Thread.sleep( 10 * 1000 );
System.out.println( "ok" );
}
catch( InterruptedExcpetion e ){}
}
...
...
public static void main( String[] args )
{
// Uma vez que 'metodo()' lança exceção, é preciso tratá-la em algum lugar
try
{
metodo();
}
catch( InterruptedException e ){}
}
// Aqui o método não trata, mas lança a exceção
private static void metodo() throws InterruptedException
{
System.out.println( "ok" );
Thread.sleep( 10 * 1000 );
System.out.println( "ok" );
}
...
Gostei + 0
17/02/2011
Ana Maruchi
Gostei + 0
17/02/2011
Javaxxx
try
{
// Somente aqui dentro vc pode utilizar o [b]sleep()[/b]
}
catch( InterrputedException e ){}
public void metodo()
{
try
{
int i = 0;
while( ++i <= 5 )
{
// Aqui o código que exibe a tela 1
Thread.sleep( 3 * 1000 );
// Aqui o código que exibe a tela 2 e entrada de dados
Thread.sleep( 15 * 1000 );
}
}
catch( InterruptedException e ){}
}
Gostei + 0
17/02/2011
Alexandre Viriato
package src.temporizador;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Janela1 extends JFrame {
private static final long serialVersionUID = 1L;
protected JButton button1 = null;
protected Janela2 janela2 = null;
public Janela1() {
initComponents();
configureLayout();
}
private void configureLayout() {
this.setSize(300, 300);
this.setLocationRelativeTo(null);
this.setLayout(new FlowLayout());
this.add(button1);
}
private void initComponents() {
button1 = new JButton("Janela2");
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
janela2 = new Janela2();
janela2.setVisible(true);
}
});
}
});
}
public static void main(String[] args) {
new Janela1().setVisible(true);
}
}
package src.temporizador;
import java.awt.FlowLayout;
import java.util.Timer;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Janela2 extends JFrame {
private static final long serialVersionUID = 1L;
protected JLabel label1 = null;
protected JTextField text1 = null;
protected Timer timer = null; //incluir
protected CloseJanelaTask task = null; //incluir
public Janela2() {
initComponents();
configureLayout();
}
private void configureLayout() {
this.setSize(300, 300);
this.setLocationRelativeTo(null);
this.setLayout(new FlowLayout());
this.add(text1);
}
private void initComponents() {
text1 = new JTextField(10);
timer = new Timer(); // incluir
task = new CloseJanelaTask(this); // incluir
timer.schedule(task, 5 * 1000); // incluir - 5 segundos para teste
}
public static void main(String[] args) {
new Janela2().setVisible(true);
}
}
package src.temporizador;
import java.util.TimerTask;
import javax.swing.JFrame;
public class CloseJanelaTask extends TimerTask {
private JFrame janela = null;
public CloseJanelaTask(JFrame janela) {
this.janela = janela;
}
@Override
public void run() {
janela.setVisible(false);
}
}
Gostei + 0
19/02/2011
Ana Maruchi
Gostei + 0
21/02/2011
Ana Maruchi
Gostei + 0
21/02/2011
Alexandre Viriato
Gostei + 0
22/02/2011
Ana Maruchi
timer = new Timer(); task = new CloseJanelaTask(this); timer.schedule(task, 5 * 1000); //o objetivo é após fechar a janela atual //Chamar uma 3a janela Janela3 janela3 = new Janela3(); janela3.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE); janela3.setVisible(true);
Gostei + 0
22/02/2011
Alexandre Viriato
timer = new Timer(); task = new CloseJanelaTask(this); timer.schedule(task, 5 * 1000); //o objetivo é após fechar a janela atual //Chamar uma 3a janela Janela3 janela3 = new Janela3(); janela3.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE); janela3.setVisible(true);
Gostei + 0
02/03/2011
Ana Maruchi
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)
Inserção de url
Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.