当前位置: 技术问答>java相关
JAVA事件处理
来源: 互联网 发布时间:2015-01-19
本文导语: public void processEvent(Event event) { //事件处理 } 我在applet写了上面的事件,但事件没有起作用,请问各位大侠是怎么回事,答对即给 分。 | public class Test extends JApplet { TestEventID = 23456;...
public void processEvent(Event event)
{
//事件处理
}
我在applet写了上面的事件,但事件没有起作用,请问各位大侠是怎么回事,答对即给
分。
{
//事件处理
}
我在applet写了上面的事件,但事件没有起作用,请问各位大侠是怎么回事,答对即给
分。
|
public class Test extends JApplet
{
TestEventID = 23456;//be careful to set this ID
TestPanel tp = new TestPanel();
...
public void sendTestMessage()
{
ActionEvent ae =new ActionEvent(viewPage,TestEventID,"A test event");
tp.dispatchEvent(ae);
}
}
Class TestPanel extends JPanel
{
TestEventID = 23456;//be careful to set this ID
...
public void processEvent(AWTEvent awte)
{
if(awte.getID()==TestEventID)
{
try
{
Thread.sleep(5000);
System.out.println("processEvnt finished");
}
catch(InterruptedException ie)
{}
}
else
super.processEvent(awte);
}//end of processEvent
}
{
TestEventID = 23456;//be careful to set this ID
TestPanel tp = new TestPanel();
...
public void sendTestMessage()
{
ActionEvent ae =new ActionEvent(viewPage,TestEventID,"A test event");
tp.dispatchEvent(ae);
}
}
Class TestPanel extends JPanel
{
TestEventID = 23456;//be careful to set this ID
...
public void processEvent(AWTEvent awte)
{
if(awte.getID()==TestEventID)
{
try
{
Thread.sleep(5000);
System.out.println("processEvnt finished");
}
catch(InterruptedException ie)
{}
}
else
super.processEvent(awte);
}//end of processEvent
}
|
你还要保证enableEvents!