Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

actionPerformed not working ??

807598Apr 5 2006 — edited Apr 6 2006
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 4 2006
Added on Apr 5 2006
9 comments
787 views