【Java开源代码栏目提醒】:网学会员Java开源代码为您提供Button3.java参考,解决您在Button3.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 Button3 {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
// ---------创建窗口中的其他界面组件-------------
for (int i = 0; i < 10; i++) {
Button button = new Button(shell, SWT.NONE);
button.setText(i + "");
button.setBounds(i * 20, 10, 20, 20); // 设置按钮位置
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Button b = (Button) e.getSource();
MessageDialog.openInformation(null, null, b.getText());
}
});
}
// -----------------END------------------------
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}