首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

SWT中的多事件监听有关问题和参数传递

2012-01-09 
SWT中的多事件监听问题和参数传递使用SWT进行毕业设计,发现对事件的监听都是,先创建一个按钮,然后后面对按

SWT中的多事件监听问题和参数传递
使用SWT进行毕业设计,发现对事件的监听都是,先创建一个按钮,然后后面对按钮添加监听,然后操作。然后再创建一按纽,再继续在后一按纽处添加监听。觉得这样很麻烦,能不能直接和SWING一样,直接在按纽后添加button1.addActionListener(this);然后统一把监听事件操作写进public   void   actionPerformed(ActionEvent   e){}中。
其次就是SWT的参数传递有点不会。简单的说就是第一个登陆界面存在一个登陆ID,那么在点确定后,跳转到下一界面,显示这个ID的信息,这个ID怎么传递?

[解决办法]
可以用Dialog
[解决办法]
你说的那个可以搞定嘛,如:

Java code
import org.eclipse.swt.SWT;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.events.SelectionListener;import org.eclipse.swt.layout.RowLayout;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;public class EventSample implements SelectionListener {    private Display display;    private Shell shell;    private Button btn1, btn2, btn3;    public EventSample() {        display = new Display();        shell = new Shell(display);        shell.setText("EVENTSAMPLE");        shell.setLayout(new RowLayout());        btn1 = new Button(shell, SWT.PUSH);        btn1.setText("BUTTON1");        btn1.addSelectionListener(this);        btn2 = new Button(shell, SWT.PUSH);        btn2.setText("BUTTON2");        btn2.addSelectionListener(this);        btn3 = new Button(shell, SWT.PUSH);        btn3.setText("BUTTON3");        btn3.addSelectionListener(this);    }    public void open() {        shell.pack();        shell.open();        while (!shell.isDisposed())            if (!display.readAndDispatch())                display.sleep();        display.dispose();    }    public void widgetDefaultSelected(SelectionEvent evnt) {    }    public void widgetSelected(SelectionEvent evnt) {        Object obj = evnt.getSource();        if (obj.equals(btn1)) {            System.out.println("BUTTON1");        } else if (obj.equals(btn2)) {            System.out.println("BUTTON2");        } else {            System.out.println("BUTTON3");        }    }    public static void main(String[] args) {        new EventSample().open();    }} 

热点排行