1

これは簡単だと思いますが、何がエラーなのかはわかりません。

    final Timer tiempo= new Timer(1000,new ActionListener()) ;

私が欲しいのは、1000 の遅延とアクション リスナーだけですが、これは完全には理解できません。問題は、常にエラーが発生することです。「未定義です。」

メソッドで

        final Timer tiempo= new Timer(1000, ActionListener() 
    { 
        public void actionPerformed(ActionEvent e) 
        {   

        }
    };    

まだ未定義になり、前にインスタンスを作成しようとしました

ActionListener actionlistener= new ActionListener();
            final Timer tiempo= new Timer(1000, actionlistener() 
    { 
        public void actionPerformed(ActionEvent e) 
        {   

        }
    };    

説明してください、これは非常にイライラします。

Error: ActionListner cannot be resolved to a variable
4

1 に答える 1

4

最初の例では、新しいものを「作成」していませんActionListener

final Timer tiempo= new Timer(1000, ActionListener() 
{ 
    public void actionPerformed(ActionEvent e) 
    {   

    }
};  

そのはずnew ActionListener()

final Timer tiempo= new Timer(1000, new ActionListener() 
{ 
    public void actionPerformed(ActionEvent e) 
    {   

    }
};  

あなたの2番目の例は、いくつかの理由で間違っています...

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) 
    {   

    }
}; 

それはもっと似ているはずです...

ActionListener actionlistener= new ActionListener()
{ 
    public void actionPerformed(ActionEvent e) 
    {   

    }
}; 
final Timer tiempo= new Timer(1000, actionlistener);
于 2013-05-07T04:16:29.227 に答える