我´我试图在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{
我甚至试着用正式的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);
}
}
暂无答案!
目前还没有任何答案,快来回答吧!