actionPerformed not working ??
807598Apr 5 2006 — edited Apr 6 2006Hi all, I have written this program to display a box for user to enter a value and display the computed value :-
import java.awt.*;
import javax.swing.*;
import java.text.*;
import java.awt.event.*;
public class ConvertMachine extends JFrame implements ActionListener
{
//class and instance variable declaration;
public static void main(String[] args)
{
new ConvertMachine();
}
public MetricMachine()
{
// Layout statements
ButtonToLeft.addActionListener(this);
ButtonToRight.addActionListener(this);
} //ConvertMachine statement
public void actionPerformed(ActionEvent evt)
{
if ( evt.getSource() == ButtonToLeft )
{
CmNumber = InchesNumber * 2.54;
nameField.setText("CM =" + CmNumber);
}
else if ( evt.getSource() == ButtonToRight )
{
InchesNumber = CmNumber / 2.54;
nameField.setText("Inches =" + InchesNumber);
}
}
After I've complied , I set a breakpoint at
" ButtonToLeft.addActionListener(this) ". When I run the program and hit the breakpoint , it proceeds to the next statement and return to
" new ConvertMachine(); " and exit.
I could not understand why the ActionListener did not call the actionPerfomed fuinction.
Can anyone assist me?
Thanks