1.在Shell上添加一个Label
Label label = new Label(shell, SWT.CENTER);
label.setText("This is a label");
label.setBounds(shell.getClientArea());
一定要setBounds,否则label不会被显示出来。
2.显示系统信息
label.setText("Platform:"+ SWT.getPlatform() + " Version:" + SWT.getVersion());
Windows下一般都是win32加一串数字
3.添加按钮:
Button button = new Button(shell, SWT.PUSH);
button.setText("Click me");
button.setBounds(10, 10, 100, 40);
4.按钮响应点击事件:
4.1通过SelectionListener:
button.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
label.setText(Integer.toString(++count));
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
4.2通过通用事件Listener
button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
switch(event.type) {
case SWT.Selection:
label.setText(Integer.toString(++count));
break;
}
}
});
Label label = new Label(shell, SWT.CENTER);
label.setText("This is a label");
label.setBounds(shell.getClientArea());
一定要setBounds,否则label不会被显示出来。
2.显示系统信息
label.setText("Platform:"+ SWT.getPlatform() + " Version:" + SWT.getVersion());
Windows下一般都是win32加一串数字
3.添加按钮:
Button button = new Button(shell, SWT.PUSH);
button.setText("Click me");
button.setBounds(10, 10, 100, 40);
4.按钮响应点击事件:
4.1通过SelectionListener:
button.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
label.setText(Integer.toString(++count));
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
4.2通过通用事件Listener
button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
switch(event.type) {
case SWT.Selection:
label.setText(Integer.toString(++count));
break;
}
}
});