я предоставляю код, который является примером кнопки счетчика, которая будет вызывать некоторый кадр через 30 секунд ..
import java.awt.event.ActionEvent;import java.awt.event.ActionListener;
/ * * Чтобы изменить этот шаблон, выберите Сервис |Шаблоны * и откройте шаблон в редакторе.* /
/ * * NewJFrame.java * * Создано 10 февраля 2011, 10:57:13 * /
/ ** * * @author win xp * / public classNewJFrame расширяет javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
initUI();
}
private javax.swing.Timer timer = null;private void initUI () {
timer = new javax.swing.Timer(1000, (ActionListener) new MyActionListener());
timer.setInitialDelay(0);
timer.start();
}
class MyActionListener implements ActionListener {
private int counter = 10;
public void actionPerformed(ActionEvent e) {
counter = counter - 1;
String text = "<html><font size=\"14\">" + String.valueOf(counter) + "</font></head>";
counterLabel.setText(text);
if (counter == 0) {
timer.stop();
jButton1ActionPerformed(null);
}
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
counterLabel = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
counterLabel.setText("jLabel1");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(149, 149, 149)
.addComponent(jButton1))
.addGroup(layout.createSequentialGroup()
.addGap(163, 163, 163)
.addComponent(counterLabel)))
.addContainerGap(178, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(77, 77, 77)
.addComponent(counterLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 81, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(105, 105, 105))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Show show = new Show();
show.setVisible(true);
this.setVisible(false);
timer.stop();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel counterLabel;
private javax.swing.JButton jButton1;
// End of variables declaration
}