当前位置: 代码迷 >> Eclipse >> eclipse SWT开发时,按钮1怎么自动触发按钮2的事件
  详细解决方案

eclipse SWT开发时,按钮1怎么自动触发按钮2的事件

热度:105   发布时间:2016-04-23 18:41:13.0
eclipse SWT开发时,按钮1如何自动触发按钮2的事件
eclipse   SWT开发时,点击按钮200时,如何自动触发按钮100的事件?
例如:
final   Button   button100   =   new   Button(shell,   SWT.NONE);
button100.addSelectionListener(new   SelectionAdapter()   {
public   void   widgetSelected(final   SelectionEvent   e)
{
MessageBox   msg   =   new   MessageBox(shell);
msg.setText( "信息100 ");
msg.setMessage(button100.getText());
msg.open();
}
});
button100.setText( "button100 ");
button100.setBounds(5,   63,   120,   30);

--按钮200的事件
final   Button   button200   =   new   Button(shell,   SWT.NONE);
button200.addSelectionListener(new   SelectionAdapter()   {
public   void   widgetSelected(final   SelectionEvent   e)
{
//在此添加触发按钮100的widgetSelected事件
                                                        //如何实现????
//--------------------------------
//

}
});
button200.setText( "button200 ");
button200.setBounds(170,   70,   120,   30);

------解决方案--------------------
你可以自己定义一个event,然后当button100监听这个event,在button200被点击的时候发出这个event.例子如下:
int self_button_event_id = 110;
button100.addListener(self_button_event_id, new Listener(){
public void handleEvent(Event arg0) {
//干点什么
}
});

在button200的widgetSelected方法中加上
button100.notifyListeners(self_button_event_id, new Event());
  相关解决方案