📄 selectonlistenerexample.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -