我似乎无法使Exit Button工作,因此我的程序无法编译。如果我注释掉与退出按钮相关的所有内容,程序将正常工作并正常运行。所有其他按钮都有效。我的退出按钮出了什么问题?
/**
* Write a description of class Converterr here.
*
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
public class Converterr
{
private JLabel usdL, pesosL, eurosL;
private JTextField usdTF, pesosTF, eurosTF;
private JButton pesosB, eurosB, exitB;
PesosButtonHandler pbHandler;
EurosButtonHandler eubHandler;
ExitButtonHandler ebHandler;
public void driver()
{
JFrame c = new JFrame ("Currency Converter");
c.setSize(400,300);
c.setDefaultCloseOperation(c.EXIT_ON_CLOSE);
//Content Pane
Container cp = c.getContentPane ( );
cp.setLayout ( new GridLayout (5,2) );
pesosL = new JLabel ("Pesos: ", SwingConstants.RIGHT);
usdL = new JLabel ("USD: ", SwingConstants.RIGHT);
eurosL = new JLabel ("Euros: ", SwingConstants.RIGHT);
usdTF = new JTextField(8);
pesosTF = new JTextField(8);
eurosTF = new JTextField(8);
pesosTF.setEditable(false);
eurosTF.setEditable(false);
pesosB = new JButton ("Convert to Pesos");
eurosB = new JButton ("Convert to Euros");
exitB = new JButton ("Exit");
// add to content pane container
cp.add(usdL);
cp.add(usdTF);
cp.add(pesosL);
cp.add(pesosTF);
cp.add(eurosL);
cp.add(eurosTF);
cp.add(pesosB);
cp.add(eurosB);
cp.add(exitB);
c.setVisible(true);
//Instantiate Listeners
pbHandler = new PesosButtonHandler();
eubHandler = new EurosButtonHandler();
ebHandler = new ExitButtonHandler();
pesosB.addActionListener(pbHandler);
eurosB.addActionListener(eubHandler);
exitB.addActionListener(ebHandler);
}
//action listener interfaces
private class PesosButtonHandler implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
double inusd;
double outpesos;
inusd = Double.parseDouble(usdTF.getText() );
outpesos = inusd * 12.31;
pesosTF.setText(Double.toString(outpesos));
}
}
private class EurosButtonHandler implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
double inusd, outeuros;
inusd = Double.parseDouble(usdTF.getText() );
outeuros = inusd * .78;
eurosTF.setText(Double.toString(outeuros));
}
}
private class ExitButtonHandler implements ActionListener
{
public void ActionPerformed (ActionEvent e)
{
System.exit(0);
}
}
public static void main (String [ ] args)
{
Converterr conv = new Converterr();
conv.driver();
}
}
Converterr.ExitButtonHandler is not abstract and does not override
abstract method actionPerformed(java.awt.event.ActionEnvt) in java.awt.event.ActionListener
答案 0 :(得分:4)
public void ActionPerformed (ActionEvent e)
方法名称中有拼写错误。它应该是:
public void actionPerformed (ActionEvent e)