标题:java中JButton组件监听单击事件问题
取消只看楼主
tudou2xigua
Rank: 2
等 级:论坛游民
帖 子:87
专家分:54
注 册:2011-3-20
结帖率:90.32%
已结贴  问题点数:20 回复次数:0 
java中JButton组件监听单击事件问题
package com.law;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
public class JButtonTest extends JFrame
{
    public JButtonTest()
    {
        setTitle("JButton组件");
        Container container=getContentPane();
        container.setLayout(new GridLayout(3,2,5,5));
        JButton jb1=new JButton("按钮");
        jb1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                JOptionPane.showMessageDialog(null,"弹出对话框");
            }
        });
        container.add(jb1);
        setBounds(100,100,300,300);
        setVisible(true);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    public static void main(String[] args)
    {
        new JButtonTest();
    }
}
程序中监听按钮单击事件,老报如下错误,明明是用的匿名类啊,为什么报错?求解。谢谢
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (new ActionListener(){})
    ActionListener cannot be resolved to a type
搜索更多相关主题的帖子: java package public import 
2011-10-23 14:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-353202-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.515950 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved