I write this blog to share the solutions and problems I have found with fellow software engineers. I also do it to remind myself of what I've already figured out ;)

Thursday, June 28, 2007

Example of javax.swing.Timer

*
* MainFrame.java
*
* Created on June 27, 2007, 9:15 AM
*/

package main;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;

/**
*
* @author Woody
*/
public class MainFrame extends javax.swing.JFrame implements ActionListener {

static Thread thread1;
static Logger log = Logger.getLogger("MainFrame");
static StringBuffer log2 = new StringBuffer();
static Timer t;

/** Creates new form MainFrame */
public MainFrame() {
initComponents();
}

/** 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.
*/
//
private void initComponents() {

}//


private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

thread1.interrupt();
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
thread1 = new Thread1();
t = new Timer(100, this);
t.setDelay(100);
t.start();
thread1.start();
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {

new MainFrame().setVisible(true);
}
});

}

public javax.swing.JButton getJButton1() {
return jButton1;
}

public void setJButton1(javax.swing.JButton jButton1) {
this.jButton1 = jButton1;
}

public javax.swing.JButton getJButton2() {
return jButton2;
}

public void setJButton2(javax.swing.JButton jButton2) {
this.jButton2 = jButton2;
}

public javax.swing.JButton getJButton3() {
return jButton3;
}

public void setJButton3(javax.swing.JButton jButton3) {
this.jButton3 = jButton3;
}

public javax.swing.JScrollPane getJScrollPane1() {
return jScrollPane1;
}

public void setJScrollPane1(javax.swing.JScrollPane jScrollPane1) {
this.jScrollPane1 = jScrollPane1;
}

public javax.swing.JTextArea getJTextArea1() {
return jTextArea1;
}

public void setJTextArea1(javax.swing.JTextArea jTextArea1) {
this.jTextArea1 = jTextArea1;
}

public void actionPerformed(ActionEvent actionEvent) {
jTextArea1.setText(log2.toString());
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration

}

No comments: