码迷,mamicode.com
首页 > 其他好文 > 详细

监听事件2

时间:2021-05-24 17:18:26      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:top   class   comm   oid   package   imp   err   pac   rri   

package cn.rushangw.lesson02;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestActonEvent2 {
public static void main(String[] args) {
Frame frame = new Frame("开始-结束");
Button button1 = new Button("start");
Button button2 = new Button("stop");

button1.setActionCommand("button1-start");
button2.setActionCommand("button2-stop");

MyMonitor myMonitor = new MyMonitor();

button1.addActionListener(myMonitor);
button2.addActionListener(myMonitor);

frame.add(button1,BorderLayout.WEST);
frame.add(button2,BorderLayout.EAST);

frame.pack();
frame.setVisible(true);

}
}
class MyMonitor implements ActionListener{

@Override
public void actionPerformed(ActionEvent e) {
//获得按钮的信息
System.out.println("按钮被点击了:msg"+e.getActionCommand());
}
}

监听事件2

标签:top   class   comm   oid   package   imp   err   pac   rri   

原文地址:https://www.cnblogs.com/nigustudent/p/14791061.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!