当前位置: 代码迷 >> Java相关 >> 怎么让某个组件上发生某事件之后然后触发别一个组件上的事件?
  详细解决方案

怎么让某个组件上发生某事件之后然后触发别一个组件上的事件?

热度:170   发布时间:2007-09-22 18:18:38.0
怎么让某个组件上发生某事件之后然后触发别一个组件上的事件?

比如,在jtextfield中按回车之后会触发actionevent事件,如何让它触发这个事件的同时,Jbutton同时响应这个事件!!

搜索更多相关的解决方案: 触发  组件  

----------------解决方案--------------------------------------------------------
直接Jbutton.addActionListener行不?
----------------解决方案--------------------------------------------------------

你如果能实现的话,能否给出代码,谢谢了!


----------------解决方案--------------------------------------------------------

呵呵,兄弟姐妹们,给个解决方案啊,又碰到类似的问题了!!


----------------解决方案--------------------------------------------------------
什么意思?
----------------解决方案--------------------------------------------------------

也就是我如何不用按按钮,就能触发此按钮上的ActionEvent事件
请教了!!


----------------解决方案--------------------------------------------------------
首先要清楚,你要触发按钮上的事件干什么,然后把要做的事写到一个方法里面,

然后在jtextfield被触发的时候,顺便调用一下那个方法
----------------解决方案--------------------------------------------------------

呵呵,由于一个程序的需要,这样做会使程序简捷些!!
JButon是用addActionlistener(),这样怎么在另外一个方法中调用啊??


----------------解决方案--------------------------------------------------------

多看JAVA DOCS~


doClick

public void doClick(int pressTime)
Programmatically perform a "click". This does the same thing as if the user had pressed and released the button. The button stays visually "pressed" for pressTime milliseconds.

Parameters:
pressTime - the time to "hold down" the button, in milliseconds



----------------解决方案--------------------------------------------------------

直接用这个:


doClick

public void doClick()
Programmatically perform a "click". This does the same thing as if the user had pressed and released the button.

----------------解决方案--------------------------------------------------------
  相关解决方案