Java报错:The type new ActionListener(){} must implement the inherited abstract method ActionListener.actionPe
第三行,import java.awt.event.ActionListener; //改为import java.awt.event.*;即可 有时ActionListener写成了ActionListerner也会报错,注意单词写正确
package e13_02;
import java.awt.*;
import java.awt.event.ActionListener; //改为import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
class MyJDialog extends JDialog{
public MyJDialog(MyFrame frame){
super(frame,"this is first JDialog window",true);
Container container=getContentPane();
container.add(new JLabel("this is dui huakuang"));
}
}
public class MyFrame extends JFrame {
public static void main(String[] args) {
// TODO Auto-generated method stub
new MyFrame();
}
public MyFrame(){
Container container=getContentPane();
container.setLayout(null);
JLabel jl=new JLabel("this is new JFrame window");
jl.setHorizontalAlignment(SwingConstants.CENTER);
container.add(jl);
JButton bl=new JButton("pop up new dialog");
bl.setBounds(10,10,100,21);
bl.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new MyJDialog(MyFrame.this).setVisible(true);
}
});
container.add(bl);
}
}