Hola muy buena noche, por favor ayúdenme con este tema, tengo un jframe el cual quiero cerrarlo a los 5 segundos que halla cargado, por favor díganme donde tengo que agitar el código si en el jframe o en una clase y como lo implemento por favor muchas gracias que tengan un buen dia
Copyright © 2024 ANSWERS.MX - All rights reserved.
Answers & Comments
Verified answer
Basicamente es así:
public class NewJFrame extends javax.swing.JFrame implements ActionListener{
/**
* Creates new form NewJFrame
*/
Timer t = null;
public NewJFrame() {
initComponents();
t = new Timer(5000, this);
t.start();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == t){
dispose();
}
}
}
Me parece que está bastante claro, inicializas el objeto Timer pasandole el tiempo en milisegundos y una fuente de actionListener, luego en el método actionPerformed haces todo lo que quieras, nos vemos!
Publica tu duda aqui, siempre ayudan :)
http://codigueando.com/foro