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

📄 toolbarclass.java

📁 jsp网络编程从基础到实践源代码
💻 JAVA
字号:
package org.cookbook.ch09;

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

public class ToolbarClass {

        public static void main(String [] args) {
            Display display = new Display();
            final Shell shell = new Shell(display);
            shell.setSize(300, 200);
            shell.setText("Toolbar Example");
            
            ToolBar toolbar = new ToolBar(shell, SWT.NONE);
			toolbar.setBounds(0, 0, 200, 70);
           
            ToolItem toolItem1 = new ToolItem(toolbar, SWT.PUSH);
            toolItem1.setText("Save");
            ToolItem toolItem2 = new ToolItem(toolbar, SWT.PUSH);
            toolItem2.setText("Save As");
            ToolItem toolItem3 = new ToolItem(toolbar, SWT.PUSH);
            toolItem3.setText("Print");
			ToolItem toolItem4 = new ToolItem(toolbar, SWT.PUSH);
			toolItem4.setText("Run");
			ToolItem toolItem5 = new ToolItem(toolbar, SWT.PUSH);
			toolItem5.setText("Help");
            
            final Text text = new Text(shell, SWT.BORDER);
            text.setBounds(55, 80, 200, 25);
            
            Listener toolbarListener = new Listener() {
                public void handleEvent(Event event) {
                    ToolItem toolItem =(ToolItem)event.widget;
                    String caption = toolItem.getText();
                    text.setText("You clicked " + caption);
               }
            };
            
            toolItem1.addListener(SWT.Selection, toolbarListener);
            toolItem2.addListener(SWT.Selection, toolbarListener);
            toolItem3.addListener(SWT.Selection, toolbarListener);
			toolItem4.addListener(SWT.Selection, toolbarListener);
			toolItem5.addListener(SWT.Selection, toolbarListener);

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

⌨️ 快捷键说明

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