博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SWT 初步试水
阅读量:6969 次
发布时间:2019-06-27

本文共 5923 字,大约阅读时间需要 19 分钟。

package swt;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.TabFolder;import org.eclipse.swt.SWT;import org.eclipse.swt.widgets.TabItem;import org.eclipse.swt.custom.ScrolledComposite;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.layout.GridLayout;public class FirstWin {    /**     * Launch the application.     * @param args     */    public static void main(String[] args) {        Display display = Display.getDefault();        Shell shell = new Shell();        shell.setSize(450, 300);        shell.setText("SWT Application");                TabFolder tabFolder = new TabFolder(shell, SWT.NONE);        tabFolder.setBounds(0, 0, 434, 261);                TabItem tbtmP_2 = new TabItem(tabFolder, SWT.NONE);        tbtmP_2.setText("p");                ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);        tbtmP_2.setControl(scrolledComposite);        scrolledComposite.setExpandHorizontal(true);        scrolledComposite.setExpandVertical(true);                Composite composite = new Composite(scrolledComposite, SWT.NONE);        composite.setLayout(new GridLayout(1, false));                Button btnB = new Button(composite, SWT.NONE);        btnB.addSelectionListener(new SelectionAdapter() {            @Override            public void widgetSelected(SelectionEvent e) {                new D1(shell, 0).open();            }        });        btnB.setText("b1");                Button btnB_1 = new Button(composite, SWT.NONE);        btnB_1.addSelectionListener(new SelectionAdapter() {            @Override            public void widgetSelected(SelectionEvent e) {                new S2(display).open();            }        });        btnB_1.setText("b2");        scrolledComposite.setContent(composite);        scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));                TabItem tbtmP = new TabItem(tabFolder, SWT.NONE);        tbtmP.setText("p1");                TabItem tbtmP_1 = new TabItem(tabFolder, SWT.NONE);        tbtmP_1.setText("p2");        shell.open();        shell.layout();        while (!shell.isDisposed()) {            if (!display.readAndDispatch()) {                display.sleep();            }        }    }}
package swt;import org.eclipse.swt.widgets.Dialog;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.SWT;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;public class D1 extends Dialog {    protected Object result;    protected Shell shell;    /**     * Create the dialog.     * @param parent     * @param style     */    public D1(Shell parent, int style) {        super(parent, style);        setText("SWT Dialog");    }    /**     * Open the dialog.     * @return the result     */    public Object open() {        createContents();        shell.open();        shell.layout();        Display display = getParent().getDisplay();        while (!shell.isDisposed()) {            if (!display.readAndDispatch()) {                display.sleep();            }        }        return result;    }    /**     * Create contents of the dialog.     */    private void createContents() {        shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.MIN | SWT.MAX);        shell.setSize(450, 300);        shell.setText(getText());                Label lblD = new Label(shell, SWT.NONE);        lblD.setBounds(92, 44, 61, 17);        lblD.setText("d1");                Button btnConcso = new Button(shell, SWT.NONE);        btnConcso.addSelectionListener(new SelectionAdapter() {            @Override            public void widgetSelected(SelectionEvent e) {                shell.close();            }        });        btnConcso.setBounds(71, 131, 80, 27);        btnConcso.setText("Cancel");    }}
package swt;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.SWT;public class C1 extends Composite {    /**     * Create the composite.     * @param parent     * @param style     */    public C1(Composite parent, int style) {        super(parent, style);                Label lblC = new Label(this, SWT.NONE);        lblC.setBounds(139, 142, 61, 17);        lblC.setText("c1");    }    @Override    protected void checkSubclass() {        // Disable the check that prevents subclassing of SWT components    }}
package swt;import org.eclipse.swt.SWT;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Label;public class S2 extends Shell {    /**     * Launch the application.     * @param args     */    public  void open(Shell shell) {        try {            Display display = getParent().getDisplay();            shell.open();            shell.layout();            while (!shell.isDisposed()) {                if (!display.readAndDispatch()) {                    display.sleep();                }            }        } catch (Exception e) {            e.printStackTrace();        }    }    /**     * Create the shell.     * @param display     */    public S2(Display display) {        super(display, SWT.SHELL_TRIM);                Label lblS = new Label(this, SWT.NONE);        lblS.setBounds(57, 55, 61, 17);        lblS.setText("s2");        createContents();    }    /**     * Create contents of the shell.     */    protected void createContents() {        setText("SWT Application");        setSize(450, 300);    }    @Override    protected void checkSubclass() {        // Disable the check that prevents subclassing of SWT components    }}

 

转载于:https://www.cnblogs.com/playboytears/p/5559209.html

你可能感兴趣的文章
jsp中的contentType与pageEncoding的区别和作用
查看>>
java 调用启动远程shell脚本,启动spark
查看>>
Spring boot ----RestTemplate学习笔记
查看>>
[LUOGU] P3128 [USACO15DEC]最大流Max Flow
查看>>
windows2003server下能安装的MSN
查看>>
Caffe将自己的文件生成lmdb
查看>>
C# 枚举中的位运算
查看>>
Codeforces Global Round 1 晕阙记
查看>>
百度文化秘籍
查看>>
Algs4-1.3.33一个双向队列Deque-双向链表实现
查看>>
Algs4-2.2.29自然的归并排序(未解决)
查看>>
shell中数组基础语法
查看>>
P1215 母亲的牛奶
查看>>
回头再看第一次项目
查看>>
有无关键字new的区别
查看>>
Hashmap,Set,Map,List,ArrayList的区别
查看>>
3.Linux 文件的压缩与打包
查看>>
JAVA分布式架构
查看>>
导入自定义模块model
查看>>
App数据分析的五大维度!
查看>>