dispactheventapplet.java
来自「这是我自己照着书上敲的」· Java 代码 · 共 54 行
JAVA
54 行
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 + =
减小字号Ctrl + -
显示快捷键?