selectonlistenerexample.java

来自「eclipse里面的每种监听器的实现.非常适合编写eclipse插件的入门者」· Java 代码 · 共 69 行

JAVA
69
字号
package com.free.event;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
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.Label;
import org.eclipse.swt.widgets.Shell;

/**
 * <p>
 * Title: Eclipse Plugin Development
 * </p>
 * <p>
 * Description: Free download
 * </p>
 * <p>
 * Copyright: Copyright (c) 2006
 * </p>
 * <p>
 * Company: Free
 * </p>
 * 
 * @author gan.shu.man
 * @version 1.0
 */

public class SelectonListenerExample {

	public static void main(String[] args) {
		Display display = new Display();

		// Create the main window
		final Shell mainShell = new Shell(display);

		// Add a button and a listener to the child shell
		Button button = new Button(mainShell, SWT.PUSH);
		button.setText("Close Me!");
		button.setBounds(10, 10, 100, 30);
		// 添加选择组件事件
		button.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent event) {
				// When the button is pressed, close the child shell
				System.out.println("select button");
				mainShell.close();
			}

			public void widgetDefaultSelected(SelectionEvent e) {
				// 不执行任何操作
			}
		});

		// Open the shells
		mainShell.open();

		while (!mainShell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
}

⌨️ 快捷键说明

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