一个事件源一个事件类只能有一个事件监听器吗?还是可以有多个事件监听器,并且事件发生时依次执行各个监听器中的事件处理代码?
比如说,
button1.addMouseListener(l1);
button1.addMouseListener(l2);
如果只能有一个事件监听器,这时button1的MouseListener是哪个?
比如说,
button1.addMouseListener(l1);
button1.addMouseListener(l2);
如果只能有一个事件监听器,这时button1的MouseListener是哪个?
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JApplet;
import javax.swing.JButton;public class ButtonOpenWebpage extends JApplet {
JButton jb = new JButton("打开我要的地址!"); ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent e) {
try {
Runtime
.getRuntime()
.exec(
"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE http://www.csdn.net");
} catch (Exception ef) {
ef.printStackTrace();
} }
};
ActionListener a2 = new ActionListener() { public void actionPerformed(ActionEvent e) {
try {
Runtime
.getRuntime()
.exec(
"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE http://www.sina.com.cn");
} catch (Exception ef) {
ef.printStackTrace();
} }
}; public void init() {
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
jb.addActionListener(al);
jb.addActionListener(a2);
cp.add(jb);
}
}
jb.addActionListener(al);
jb.addActionListener(a2);
这个前后顺序