Your code says the class "implements ActionListener". That means you're entered into a contract to implement the methods defined in that interface. Of course, the "abstract" part saves you from actually doing that.
To be honest, this is one of the strangest ways I've ever seen to fire up a form. Static is bad. Firing up another thread is senseless. And, for your listener to work, it helps to have a object that's willing to listen.
Here's an example
java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class SpringDemo1 extends JFrame implements ActionListener {
// this is our text box, we may want to keep track of it
private JTextField buildUpTextField = null;
// this is a JFrame, use it!
public SpringDemo1() {
super("SpringDemo1");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = getContentPane();
SpringLayout layout = new SpringLayout();
contentPane.setLayout(layout);
JLabel buildUpLabel = new JLabel("buildup DPs: ");
buildUpTextField = new JTextField("0", 5);
// add the listener
buildUpTextField.addActionListener(this);
contentPane.add(buildUpLabel);
contentPane.add(buildUpTextField);
layout.putConstraint(SpringLayout.WEST, buildUpLabel,5,SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, buildUpLabel,5,SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.WEST, buildUpTextField,24, SpringLayout.EAST, buildUpLabel);
layout.putConstraint(SpringLayout.NORTH, buildUpTextField,5, SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.EAST, contentPane,500,SpringLayout.EAST, buildUpTextField);
layout.putConstraint(SpringLayout.SOUTH, contentPane,500,SpringLayout.SOUTH, buildUpTextField);
pack();
}
// actions fire here
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src==this.buildUpTextField) {
System.out.println("Text Action!");
}
}
public static void main(String[] args) {
JFrame frm = new SpringDemo1();
frm.setVisible(true);
}
}
This post has been edited by baavgai: 3 Jul, 2009 - 04:26 AM