在一个类中放置actionPerformed方法的位置? [英] Where to place actionPerformed method in a class?

查看:52
本文介绍了在一个类中放置actionPerformed方法的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读了两章后,我对actionPerformed方法应该去哪里一无所知,在一本书中,我在私有内部类中看到它,在公共类中(创建一个框架)。在另一本书中,我在使用@override注册监听器后立即看到它。希望我足够清楚,否则我可以举例。



i我看到一本书:

button.addActionListener(new ActionListner() {

@override

public void actionPerformed(ActionEvent e){

// code

//

}

});

------------------------ ----------------

在另一个:

button.addActionListener(new CalcButtonListen())

//

//

//然后在课程结束时,创建一个私人课程



私有类CalcButtonListen实现ActionLIstener {

public void actionPerformed(ActionEvent e){

// code

//

}

}

After reading two chapters i am clueless as to where the actionPerformed method should go, in one book i see it in a private inner class, inside a public class(which creates a frame). In the other book i see it right after the listener is registered using @override. Hopefully i am clear enough, otherwise i can give examples.

i one one book i see:
button.addActionListener(new ActionListner(){
@override
public void actionPerformed(ActionEvent e){
//code
//
}
});
----------------------------------------
in the other:
button.addActionListener(new CalcButtonListen())
//
//
//then at the end of the class, a private class is created

private class CalcButtonListen implements ActionLIstener{
public void actionPerformed(ActionEvent e){
//code
//
}
}

推荐答案

请参阅: http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html [ ^ ]。



-SA


这篇关于在一个类中放置actionPerformed方法的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆