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
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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
1 2 3 4 5 6 7 8 9 10 11 | package p; public class ClasseC extends javax.swing.JFrame { public Saques() { initComponents(); Thread.sleep( 10 * 1000 ); // dá erro, }} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ... 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 ){} } ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ... 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
1 2 3 4 5 | try { // Somente aqui dentro vc pode utilizar o [b]sleep()[/b] } catch( InterrputedException e ){} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 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); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | 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); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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
1 2 3 4 5 6 7 8 | 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
1 2 3 4 5 6 7 8 | 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.