📄 dispactheventapplet.java
字号:
import java.applet.Applet;
/*
* Created on 2007-9-14
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.awt.*;
import java.awt.event.*;
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class DispacthEventApplet extends Applet {
Button first,second;
public void init()
{
first=new Button("发送事件");
second=new Button("处理事件");
first.addActionListener(new Listener());
second.addActionListener(new Listener());
add(first);
add(second);
this.setBackground(Color.lightGray);
}
class Listener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==first)
{
first.dispatchEvent(new ActionEvent(
second,ActionEvent.ACTION_PERFORMED,""));
showStatus("准备发送事件");
}
else
{
showStatus("正在处理事件");
try
{
Thread.currentThread().sleep(2000);
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -