button2.java

来自「SWTJFace篇项目源程序该项目包含 包含了Eclipse下构建swt的基本」· Java 代码 · 共 37 行

JAVA
37
字号
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 Button2 {
	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++) {
			final 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) {
					MessageDialog.openInformation(null, null, button.getText());
				}
			});
		}
		// -----------------END------------------------
		shell.layout();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?