首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Timer/ActionListener用法

Timer/ActionListener用法
EN

Stack Overflow用户
提问于 2013-05-07 12:10:53
回答 1查看 8.3K关注 0票数 1

我想这很简单,但我真的不能说出错误是什么。

代码语言:javascript
复制
    final Timer tiempo= new Timer(1000,new ActionListener()) ;

我唯一想要的是,1000的延迟和一个动作监听器,我不完全理解。问题是我总是得到一个错误。“还没有定义。”

使用该方法

代码语言:javascript
复制
        final Timer tiempo= new Timer(1000, ActionListener() 
    { 
        public void actionPerformed(ActionEvent e) 
        {   

        }
    };    

仍然没有定义,之前也尝试过创建一个实例

代码语言:javascript
复制
ActionListener actionlistener= new ActionListener();
            final Timer tiempo= new Timer(1000, actionlistener() 
    { 
        public void actionPerformed(ActionEvent e) 
        {   

        }
    };    

请解释一下,这是非常令人沮丧的。

代码语言:javascript
复制
Error: ActionListner cannot be resolved to a variable
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-07 12:16:29

代码语言:javascript
复制
final Timer tiempo= new Timer(1000, ActionListener() 
{ 
    public void actionPerformed(ActionEvent e) 
    {   

    }
};  

应该是new ActionListener()

代码语言:javascript
复制
final Timer tiempo= new Timer(1000, new ActionListener() 
{ 
    public void actionPerformed(ActionEvent e) 
    {   

    }
};  

你的第二个例子是错误的,原因有很多……

代码语言:javascript
复制
ActionListener actionlistener= new ActionListener(); // This won't compile
// because it is an interface and it requires either a concrete implementation
// or it's method signatures filled out...

// This won't work, because java sees actionlistener() as method, which does not
// exist and the rest of the code does not make sense after it (to the compiler)
final Timer tiempo= new Timer(1000, actionlistener() 
{ 
    public void actionPerformed(ActionEvent e) 
    {   

    }
}; 

它应该看起来更像..。

代码语言:javascript
复制
ActionListener actionlistener= new ActionListener()
{ 
    public void actionPerformed(ActionEvent e) 
    {   

    }
}; 
final Timer tiempo= new Timer(1000, actionlistener);
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16411073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档