⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eventdemo.java

📁 eclipse SWT 编程入门经典代码。分别有按钮
💻 JAVA
字号:
package swtjfacesample;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.events.*;

public class EventDemo {
 
    private Shell _shell;

    public EventDemo() {
         Display display = new Display();
         Shell shell = new Shell(display,SWT.SHELL_TRIM);
        setShell(shell);
    RowLayout layout=new RowLayout();
   shell.setLayout(layout);
   shell.setText("Event demo");
         
        Button button=new Button(shell,SWT.PUSH | SWT.CENTER);
         button.setText("Click me!");
 
         button.addSelectionListener(new SelectionListener(){
 
           public void widgetSelected(SelectionEvent event) {
                handleSelectionEvent();
            }
 
           public void widgetDefaultSelected(SelectionEvent event) {
            }     
        });
         shell.setBounds(200,300,100,100);
        shell.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
       }
        display.dispose();    
       
     }
 
    protected void handleSelectionEvent() {
         MessageBox dialog=new MessageBox(getShell(),SWT.OK|SWT.ICON_INFORMATION);
        dialog.setText("Hello");
        dialog.setMessage("Hello,world!");
         dialog.open();
     }

    /**
     * @param args
      */
    public static void main(String[] args) {
 
        EventDemo eventdemo=new EventDemo();
    }

    /**
     * @return Returns the _shell.
    */
    public Shell getShell() {
        return _shell;
    }

    /**
     * @param _shell The _shell to set.
     */
    public void setShell(Shell shell) {
        this._shell =shell;
    }
 }

⌨️ 快捷键说明

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