您当前的位置: 首页 > 

txwtech

暂无认证

  • 0浏览

    0关注

    813博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

The type new ActionListener(){} must implement the inherited abstract method ActionListener.actionPe

txwtech 发布时间:2017-01-06 14:53:57 ,浏览量:0

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);
	}
}

关注
打赏
1665060526
查看更多评论
立即登录/注册

微信扫码登录

0.1603s