当我尝试编译下面的代码时,它告诉我它不是抽象类,并且不重写抽象方法actionPerformed。我该如何解决?如何解决抽象类错误
这里是我试图编译代码:
import java.awt.*;
import java.awt.event.*;
public class FinalProj1 extends Frame implements ActionListener
{
static FinalProj1 objFrame;
static Button objButton1;
static Button objButton2;
static TextField count = new TextField(20);
static TextField count2 = new TextField(20);
static Label objLabel;
static Label objLabel2;
FinalProj1()
{
setTitle("Click Counter");
setSize(400,400);
show();
}
public static void main(String args[])
{
objFrame= new FinalProj1();
objButton1= new Button("Agree");
objButton2= new Button("Dissagree");
objLabel= new Label();
objLabel2= new Label();
objLabel2.setText("Mexican Food Is Better Than Chineese Food");
objButton1.setBounds(110,175,75,75);
objButton2.setBounds(190,175,75,75);
objLabel2.setBounds(80,95, 250,25);
objFrame.add(objButton2);
objFrame.add(objButton1);
objFrame.add(objLabel2);
objFrame.add(objLabel);
objButton1.addActionListener(objFrame);
objButton2.addActionListener(objFrame);
int numClicks = 0;
int numClicks2 = 0;
}
@Override
public void actionPerformed(ActionEvent e);
{
objButton1.addActionListener(this);
objButton2.addActionListener(this);
if(e.getSource()==objButton1)
{
numClicks++;
}
else
{
numClicks2++;
}
count.setText("There are " + numClicks + " who agree");
count2.setText("There are " + numClicks2 + " who dissagree");
}
}
'不重写抽象方法actionPerformed' ... –
如果你不打算实现它的方法,你为什么让你的类实现'ActionListener'? –
'actionPerformed(ActionEvent);'现在你正试图调用这个方法,然后你只需要一段代码。 2不像你认为的那样链接。 (我认为 :))。 – csmckelvey