fd bottom = new FormAttachment(btSort );
numGroup setLayoutData(fd);
// Label for input numbers
Label numLabel = new Label(numGroup SWT WRAP);
numLabel
setText( Please input the numbers you want to sort: (Note: Numbers need to be seperated by space) );
fd = new FormData();
fd top = new FormAttachment( );
fd left = new FormAttachment( );
fd right = new FormAttachment( );
numLabel setLayoutData(fd);
// Text for input numbers
numText = new Text(numGroup SWT BORDER | SWT MULTI | SWT V_SCROLL
| SWT WRAP);
numText setToolTipText( Numbers need to be seperated by space );
fd = new FormData();
fd top = new FormAttachment(numLabel );
fd left = new FormAttachment( );
fd right = new FormAttachment( );
fd bottom = new FormAttachment( );
numText setLayoutData(fd);
// The results group
Group resGroup = new Group(shell SWT NONE);
resGroup setText( The results: );
resGroup setLayout(layout);
fd = new FormData();
fd top = new FormAttachment(btSort );
fd left = new FormAttachment( );
fd right = new FormAttachment( );
fd bottom = new FormAttachment( );
resGroup setLayoutData(fd);
// Label for results
Label resLabel = new Label(resGroup SWT WRAP);
resLabel
setText( The results after sorted are: (Note: Results are seperated by space) );
fd = new FormData();
fd top = new FormAttachment( );
fd left = new FormAttachment( );
fd right = new FormAttachment( );
resLabel setLayoutData(fd);
// Text for results
resText = new Text(resGroup SWT BORDER | SWT MULTI | SWT V_SCROLL
| SWT WRAP);
resText setToolTipText( Results are seperated by space );
resText setEditable(false);
fd = new FormData();
fd top = new FormAttachment(resLabel );
fd left = new FormAttachment( );
fd right = new FormAttachment( );
fd bottom = new FormAttachment( );
resText setLayoutData(fd);
// Label for showing error message
errorLabel = new Label(shell SWT NONE);
fd = new FormData();
fd top = new FormAttachment( );
fd left = new FormAttachment( );
fd right = new FormAttachment( );
fd bottom = new FormAttachment( );
errorLabel setLayoutData(fd);
errorLabel setForeground(display getSystemColor(SWT COLOR_RED));
// Listen to the numText change
numText addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
numString = numText getText() trim();
hasError = false;
}
});
// If press Return focus go to Start Sort button and start sort
numText addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e keyCode == \r ) {
e doit = false;
btSort setFocus();
startSort();
}
}
});
// Listen to the button selection
btSort addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
startSort();
}
});
shell open();
while (!shell isDisposed()) {
if (!display readAndDispatch())
display sleep();
}
display dispose();
}
/**
* Get double values from string
*/
public void getDoubleFromString() {
int index = ;
// Split string using space
String[] splitedNumbers = numString split( );
if (numList size() != )
// Clear the arrayList for last used
numList clear();
for (int i = ; isplitedNumbers length; i++) {
if (splitedNumbers[i] trim() length() != ) {
try {
numList add(index++ Double valueOf(splitedNumbers[i]));
} catch (NumberFormatException e) {
setErrorMessage( Please input the correct numbers );
推荐阅读
- 无法安装sqlserver,无法安装sqlserver此目录是压缩目录
- java塔罗牌代码,judtice塔罗牌
- 龙哥无人直播在线直播,龙哥
- go语言高并发教程 go 并发
- 装系统boot怎么设置u盘启动,装系统boot怎么设置u盘启动
- 主播怎么在直播间发表情包,主播怎么在直播间发表情包呢
- 神经网络逼近函数c语言 c语言 神经网络
- jquery右侧导航,js导航栏左右滑动
- flutterweb相互调用,flutter和webview交互