java addactionlistener使用_java – 为什么addActionListener方法需要这些阶段?

b.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ea){

System.exit(0);

}

});

我正在学习Java并看到上面的代码.

我无法理解为什么addActionlisetner方法需要Actionlistener作为参数.

使用System.exit(0)不是更简单吗?

解决方法:

您可以使用API Java作为参考来查找问题的答案.

public void addActionListener(ActionListener l)

Adds an ActionListener to the button.

Parameters:

l – the ActionListener to be added

例如,具体类JButton从类javax.swing.AbstractButton继承了方法addActionListener(ActionListener l).

当你这样做时:

new ActionListener(){

public void actionPerformed(ActionEvent ea){

System.exit(0);

}

}

您正在创建ActionListener的anonymous subclass的实例.

ActionListener是用于接收动作事件的接口.

The class that is interested in processing an action event implements this interface, and the object created with that class is registered with a component, using the component’s addActionListener method. When the action event occurs, that object’s actionPerformed method is invoked.

标签:actionlistener,system-exit,java,arguments

来源: https://codeday.me/bug/20190829/1760067.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值