我能';我没有在java中使用按钮,我甚至尝试过使用文档方法,但什么都没有
我试图在Java的GUI中使用按钮,我导入了所有必要的类,我编译Java时显示了下一个错误:我能';我没有在java中使用按钮,我甚至尝试过使用文档方法,但什么都没有,java,swing,user-interface,button,Java,Swing,User Interface,Button,我试图在Java的GUI中使用按钮,我导入了所有必要的类,我编译Java时显示了下一个错误: Botones.java:4: error: Botones is not abstract and does not override abstract method actionPerfomed(ActionEvent) in ActionListener public class Botones extends JFrame implements ActionListener{ 我甚至
Botones.java:4: error: Botones is not abstract and does not override
abstract method actionPerfomed(ActionEvent) in ActionListener
public class Botones extends JFrame implements ActionListener{
我甚至试着用官方的oraclejava文档方法()来实现它,但仍然不起作用
我的代码在这里:
import javax.swing.*;
import java.awt.event.*;
public class Botones extends JFrame implements ActionListener{
JButton boton1;
public Botones(){
setLayout(null);
boton1 = new JButton("Cerrar");
boton1.setBounds(200,100,50,25);
add(boton1);
boton1.addActionListener(this);
}
public void actionPerfomed(ActionEvent evento){
if(evento.getSource() == boton1){
System.exit(0);
}
}
public static void main(String args[]){
Botones window1 = new Botones();
window1.setBounds(0,0,900,400);
window1.setLocationRelativeTo(null);
window1.setResizable(false);
window1.setVisible(true);
}
}
您在
actionPerformed(…)
方法名称上有拼写错误。您缺少一个“r”。另外,不要使用空布局。Swing设计用于布局管理器。您也不应该扩展JFrame。学习正确的编码技术,从中找到的例子是的,我已经纠正了我的程序感谢你。对不起,我的愚蠢,但我是一个新手,我真的很想学习我总是打字错误。您只需要理解消息告诉您的内容,以便下次发现问题。@camickr是否修复了拼写错误并解决了问题?@DDmor提示是在您尝试覆盖的方法上方的行中添加@Override
。如果重写的方法不存在,编译器将给您一个错误。