【发布时间】:2016-09-16 16:29:34
【问题描述】:
我的问题如下。我想这是一个相当容易的问题。然而,在谷歌上花了几个小时搜索解决方案后,我仍然没有答案。
我有一个函数createGui,我给它一个字符串变量text。此函数创建一个 GUI,用户可以在其中单击按钮。每当他单击按钮时,我都想修改变量text。我还想将标签label 设置为text 的值。最后,我想返回这么修改的变量text。
你能告诉我,如何实现我的目标吗?
public String createGui(String text)
{
Display display = new Display();
Shell shell = new Shell( display );
shell.setLayout( new GridLayout( 1, false ) );
Label label = new Label( shell, SWT.NONE );
label.setText( "abc" );
Button b = new Button( shell, SWT.CHECK );
b.setText( "check" );
b.addSelectionListener( new SelectionAdapter()
{
@Override
public void widgetSelected( SelectionEvent e )
{
// modify text
// change label to text
}
} );
shell.pack();
shell.open();
while( !shell.isDisposed() )
{
if( !display.readAndDispatch() )
{
display.sleep();
}
}
display.dispose();
return text;
}
【问题讨论】: