?? button1.java
字號:
package cn.com.chengang.swt;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Button1 {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
// ---------創建窗口中的其他界面組件-------------
final Button radio1 = new Button(shell, SWT.RADIO);// 事件代碼里要訪問radio1,所以加一個final
radio1.setText("男");// 設置按鈕上的文字
radio1.setSelection(true);// 設置按鈕處于選擇狀態
radio1.setBounds(10, 10, 40, 25); // 設置按鈕位置
final Button radio2 = new Button(shell, SWT.RADIO);
radio2.setText("女");
radio2.setBounds(10, 30, 40, 25);
final Button check1 = new Button(shell, SWT.CHECK);
check1.setText("旅游");
check1.setBounds(70, 10, 40, 25);
final Button check2 = new Button(shell, SWT.CHECK);
check2.setText("籃球");
check2.setBounds(70, 30, 40, 25);
Button okButton = new Button(shell, SWT.NONE);
okButton.setText("確定");
okButton.setBounds(10, 70, 100, 25);
okButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String str = "小明,";
if (radio1.getSelection())// 判斷按鈕是否被選
str += radio1.getText();// 取得按鈕上的文字
if (radio2.getSelection())
str += radio2.getText();
str += "。愛好:";
if (check1.getSelection())
str += check1.getText();
if (check2.getSelection())
str += check2.getText();
// 信息提示框的第一、二個參數為空值也是可以的
MessageDialog.openInformation(null, null, str);
}
});
// -----------------END------------------------
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -