package demotest;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
/**
*
* @author mositure
* 切换按钮 箭头按钮
*/
public class Test_three {
/**
* @param args
*/
public static void main(String[] args) {
//定义Display
Display display = new Display();
//创建窗口
Shell shell = new Shell(display,SWT.SHELL_TRIM);
shell.setSize(500, 750);
shell.setText("分组实列");
//设置窗口布局
shell.setLayout(new FillLayout(SWT.VERTICAL));
//在当前窗口创建分组
Group group = new Group(shell, SWT.SHADOW_ETCHED_OUT);
group.setText("设置组名");
group.setLayout(new FillLayout(SWT.VERTICAL));
//切换按钮
Button button = new Button(group,SWT.TOGGLE|SWT.LEFT);
button.setText("SWT.LEFT");
button.setToolTipText("SWT.LEFT");
Button button1 = new Button(shell,SWT.TOGGLE|SWT.FLAT);
button1.setText("SWT.FLAT");
button1.setToolTipText("SWT.FLAT");
Button button2 = new Button(shell,SWT.TOGGLE|SWT.BORDER);
button2.setText("SWT.BORDER");
button2.setToolTipText("SWT.BORDER");
//箭头按钮 SWT.UP 上| SWT.DOWN 下| SWT.LEFT 左|SWT.RIGHT 右|SWT.FLAT 中|SWT.BORDER|
Button button3 = new Button(shell,SWT.ARROW|SWT.UP);
button3.setText("SWT.LEFT");
button3.setToolTipText("SWT.LEFT");
//单选按钮
Button button4 = new Button(shell,SWT.RADIO|SWT.UP);
button4.setText("SWT.LEFT");
button4.setToolTipText("SWT.LEFT");
//多选按钮
Button button5 = new Button(shell,SWT.CHECK|SWT.UP);
button5.setText("SWT.LEFT");
button5.setToolTipText("SWT.LEFT");
//多选实列
final Button[] buttons = new Button[4];
String[] str = {"多选1","多选2","多选3","多选4"};
for(int i=0;i<buttons.length;i++){
buttons[i] = new Button(shell,SWT.CHECK);
buttons[i].setText(str[i]);
}
Button bt = new Button(shell, SWT.NONE);
bt.setText("OK");
bt.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
//循环所有按钮
for(int j=0;j<buttons.length;j++){
//如果选中则输出选中的值
if(buttons[j].getSelection()){
System.out.println("您选择了:"+buttons[j].getText());
}
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
});
group.getLayout();
shell.getLayout();
//打开主窗体
shell.open();
// shellDig.open();
//如果主窗体没有关闭
while(!shell.isDisposed()){
//如果display不忙
if(!display.readAndDispatch()){
//休眠
display.sleep();
}
}
//销毁display
display.dispose();
}
}