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());