打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
第一个SWT程序
import org.eclipse.swt.SWT;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.events.SelectionListener;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Group;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.List;import org.eclipse.swt.widgets.MessageBox;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Text;public class HelloSWT extends Shell{        // 这些都是在下面将要用到的控件    private static Text text;    private static Button swtButton;    private static Button awtButton;    private static Button swingButton;    private static Group group;    private static Button button;    private static Label benefitOfSwtLabel;    private static List list;    public static void main(String[] args) {        /**         * 创建一个Display对象,并使用这个Display创建一个         * 窗口Shell,并设置它的标题和窗口初始尺寸。因为当         * 前线程创建了Display对象,所以它是界面线程         */        Display display = Display.getDefault();        final Shell shell = new Shell(display);        shell.setText("Hello SWT");        shell.setSize(260, 283);                shell.open();                /**         * 创建一个Text空间并设置其中文字的内容。然后设置了         * 空间在窗口中的位置         * 左上顶点为(10,8),宽度为230,高度为35         */        text = new Text(shell, SWT.BORDER);        text.setText("SWT是Eclipse平台使用的图形工具箱");        text.setBounds(10, 8, 230, 35);                /**         * List控件可以用来展示一系列的内容。这里创建了4条内容         * 的List控件         */        list = new List(shell, SWT.BORDER);        list.setItems(new String[] {            "使用操作系统本地控件",            "提供一套平台无关的API",            "GUI程序的运行速度快",            "更多更多......"        });                /**         * Label控件可以在界面上展示不能修改的文字,通常作为         * 标签来使用         */        benefitOfSwtLabel = new Label(shell, SWT.NONE);        benefitOfSwtLabel.setText("SWT的优点:");        benefitOfSwtLabel.setBounds(10, 49, 90, 15);                /**         * Group对象可以用来把相关的控件组成一组,在这一组控件         * 的外面会显示出一个边框,将它们和其他控件隔离开来。在边框         * 上可以加入文字标题以说明这一组控件的作用。         */        group = new Group(shell, SWT.NONE);        group.setText("你使用过哪些图形工具箱?");        group.setBounds(10, 159, 230, 47);                /**         * Button类型包含普通按钮,单选按钮,复选按钮等很多形式。         *          */        awtButton = new Button(group, SWT.CHECK);        awtButton.setText("AWT");        awtButton.setBounds(10, 20, 54, 18);                swingButton = new Button(group, SWT.CHECK);        swingButton.setText("Swing");        swingButton.setBounds(70, 22, 60, 15);                swtButton = new Button(group, SWT.CHECK);        swtButton.setBounds(136, 22, 62, 15);        swtButton.setText("SWT");                button = new Button(shell, SWT.None);        button.addSelectionListener(new SelectionListener() {                        @Override            public void widgetSelected(SelectionEvent arg0) {                MessageBox messageBox =                         new MessageBox(shell, SWT.ICON_INFORMATION);                messageBox.setMessage("Hello SWT");                messageBox.open();            }                        @Override            public void widgetDefaultSelected(SelectionEvent arg0) {                // TODO Auto-generated method stub                            }        });                button.setText("按一下按钮,向SWT说Hello!");        button.setBounds(10, 214, 227, 25);        shell.layout();                while(!shell.isDisposed()) {            if (!display.readAndDispatch()) {                display.sleep();            }        }    }}
来源:https://www.icode9.com/content-1-599801.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Swt常用控件中文教程
采用SWT实现系统文件夹的树形结构显示
Eclipse RCP 开发:从登录对话框说开去 - 海边沫沫 - BlogJava
JAVA.SWT/JFace: SWT布局管理器
Java实现类MSN、QQ好友上线通知界面
使用DecoratedField装饰SWT
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服