-1
import java.awt.*; //Container, GridLayout, *, or etc...
import javax.swing.*; //JFrame, JLabel, *, or etc...
import java.awt.event.*;
public class NumerologyEC extends JFrame
{
    private static final int Width = 400;
    private static final int Height = 100;

    private JLabel wordJL;
    private JTextField wordTF;

    private JButton calculateJB, exitJB;

    private CalculateButtonHandler cbHandler;
    private ExitButtonHandler ebHandler;

   public  NumerologyEC()
   {
       setTitle ("Numerology Extra Credit");
       wordJL = new JLabel ("Enter a word: ", SwingConstants.RIGHT);

       wordTF = new JTextField(10);

       calculateJB = new JButton ("Calculate");
       cbHandler = new CalculateButtonHandler();
       calculateJB.addActionListener (cbHandler);

       exitJB = new JButton ("Exit");
       ebHandler = new ExitButtonHandler();
       exitJB.addActionListener (ebHandler);

       Container pane = getContentPane();
       pane.setLayout (new GridLayout (2, 2));

       pane.add(wordJL);
       pane.add(wordTF);
       pane.add(calculateJB);
       pane.add(exitJB);

       setSize(Width, Height);
       setVisible (true);
       setDefaultCloseOperation (EXIT_ON_CLOSE);
    }

      private class CalculateButtonHandler  implements ActionListener
    {
        public void actionPerformed (ActionListener e)
        {
            String word;

            word = String.parseString (wordTF.getText());
        }
    }

    private class ExitButtonHandler implements ActionListener
    {
        public void actionPerfromed (ActionEvent e)
        {
          System.exit (0);  
        }
    }

   public static void main (String[] args)
   {
    NumerologyEC rectObject = new NumerologyEC();
    }


}

i keep getting an error on the "private class CalculateButtonHandler implemets ACtionListener"

What am i missing?

2
  • 4
    public void actionPerformed (ActionListener e) should be public void actionPerformed (ActionEvent e). Also, check your z-key, it seems broken.
    – exception1
    Mar 7, 2014 at 0:12
  • 2
    Also, "actionPerformed" isn't spelled correctly in the ExitButtonHandler class.
    – Solace
    Mar 7, 2014 at 0:13

1 Answer 1

1

be careful,the Method in ExitButtonHandler is wrong:

public void actionPerfromed (ActionEvent e)
{
  System.exit (0);  
}     

The correct spelling is:

actionPerformed(ActionEvent e)
{
  System.exit(0);
}

second: the method in the CalculateButtonHandler is wrong,the right method is

public void actionPerfromed (ActionEvent e)
{

}     

not

public void actionPerfromed (ActionListener e)
{

}    

also the code

word = String.parseString (wordTF.getText());

is wrong, String class doesn't have the parseString() method. I think you want have get the input from the input TextArea and cast it to String, why not have the word=wordTF.getText(), because the wordTF.getText() is a String.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.