I am getting an error that says "The type Chapter165 must implement the inherited abstract method ActionListener.actionPerformed(Action Event). Can someone help me with where I went wrong?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Chapter165 extends JFrame implements ActionListener
{
private JTextField inputMile = new JTextField(10);
private JTextField outputKm = new JTextField(10);
private Chapter165(JTextField inputField, JTextField outputField)
{
this.inputMile = inputMile; this.outputKm = outputField;
}
public Chapter165()
{
Chapter165 listener = new Chapter165(inputMile, outputKm);
inputMile.addActionListener(listener);
outputKm.addActionListener(listener);
//... Create content panel, set layout, add components
JPanel content = new JPanel();
content.setLayout(new GridLayout(2, 2));
content.add(new JLabel("Mile"));
content.add(inputMile);
content.add(new JLabel("Kilometer"));
content.add(outputKm);
//... Set window characteristics
setContentPane(content);
pack();
setLocationRelativeTo(null);
setTitle("Exercise16_5");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
class ConvertListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == inputMile)
{
double input = Double.parseDouble(inputMile.getText());
double milesKm = input * 1.6903;
inputMile.setText("" + (input*1.6093));;
}
else if(e.getSource() == outputKm)
{
double input = Double.parseDouble(outputKm.getText());
double milesKm = input * 1.6903;
outputKm.setText("" + (input*0.6213882));
}
}
}
public static void main(String[] args)
{
JFrame window = new Chapter165();
}
}