adding a actionListener but not using inner class
Hi ,
I just wonder if I can add ActionListener to a JButton without having to implement it using an inner class. My Code is something like:
Code:
purchaseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("PURCHASE" )&& user!= null && stationFrom != null &&
stationTo != null && startTime != null && endTime != null)
{
text.setText("PURCHASE SELECTED");
} else {
text.setText("Some space are in blank PURCHASE SELECTED");
}
}
});
and I really need to implement this not as a inner class because I need to invoke another methods on other classes and everytime when I do this using the inner class basically gives me an errors and ask to define any variable inside the inner class a final variable. I haven't been able to find a example of adding the actionListener without using inner class. Can this is be done. Thanks.....