• MyEclipsse 使用Jigloo插件开发SWT应用


    安装Jigloo插件的步骤在此省略。

    首先建一个Java项目,命名为Converter。其效果是制作出一个图形界面,向其输入一段文字,可以将此段文字倒序显示出来。

    建立一个java文件,代码如下:

    package main;
    
    public class Converter {
        public static String doConvert(String input) {
            String output = "";
            char[] input0 = input.toCharArray();
            for (int i = input0.length - 1; i >= 0; i--) {
                output += input0[i];
            }
            return output;
        }
    }

      然后在创建一个SWT Composite。它的本质为java文件,不过可以使用Form Editor将其转化为图形化开发界面。

    使用图形开发界面,设计出下图画布布局:

    使用最终代码如下:

    package main;
    
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Text;
    import org.eclipse.swt.graphics.Point;
    import org.eclipse.swt.graphics.Rectangle;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    
    /**
     * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
     * Builder, which is free for non-commercial use. If Jigloo is being used
     * commercially (ie, by a corporation, company or business for any purpose
     * whatever) then you should purchase a license for each developer using Jigloo.
     * Please visit www.cloudgarden.com for details. Use of Jigloo implies
     * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
     * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
     * ANY CORPORATE OR COMMERCIAL PURPOSE.
     */
    public class NewComposite extends org.eclipse.swt.widgets.Composite {
    	private Text text1;
    	private Button OK;
    	private Text text2;
    
    	/**
    	 * Auto-generated main method to display this
    	 * org.eclipse.swt.widgets.Composite inside a new Shell.
    	 */
    	public static void main(String[] args) {
    		showGUI();
    	}
    
    	/**
    	 * Overriding checkSubclass allows this class to extend
    	 * org.eclipse.swt.widgets.Composite
    	 */
    	protected void checkSubclass() {
    	}
    
    	/**
    	 * Auto-generated method to display this org.eclipse.swt.widgets.Composite
    	 * inside a new Shell.
    	 */
    	public static void showGUI() {
    		Display display = Display.getDefault();
    		Shell shell = new Shell(display);
    		NewComposite inst = new NewComposite(shell, SWT.NULL);
    		Point size = inst.getSize();
    		shell.setLayout(new FillLayout());
    		shell.layout();
    		if (size.x == 0 && size.y == 0) {
    			inst.pack();
    			shell.pack();
    		} else {
    			Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
    			shell.setSize(shellBounds.width, shellBounds.height);
    		}
    		shell.open();
    		while (!shell.isDisposed()) {
    			if (!display.readAndDispatch())
    				display.sleep();
    		}
    	}
    
    	public NewComposite(org.eclipse.swt.widgets.Composite parent, int style) {
    		super(parent, style);
    		initGUI();
    	}
    
    	private void initGUI() {
    		try {
    			this.setLayout(null);
    			this.setSize(251, 151);
    			{
    				text1 = new Text(this, SWT.NONE);
    				text1.setBounds(48, 18, 161, 30);
    			}
    			{
    				text2 = new Text(this, SWT.NONE);
    				text2.setBounds(48, 71, 161, 30);
    			}
    			{
    				OK = new Button(this, SWT.PUSH | SWT.CENTER);
    				OK.setText("OK");
    				OK.setBounds(98, 113, 60, 30);
    				OK.addSelectionListener(new SelectionAdapter() {
    					public void widgetSelected(SelectionEvent evt) {
    						System.out.println("OK.widgetSelected, event="+evt);
    						//TODO add your code for OK.widgetSelected
    						text2.setText(Converter.doConvert(text1.getText()));//此为需要手动添加的代码
    					}
    				});
    			}
    			this.layout();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    }
    

      程序的运行结果如下图:

     

    相信自己

  • 相关阅读:
    sublime text 怎么浏览包
    postman 中url有动态变换的值时,可以按下面方式变换。
    mac jmeter安装
    mysql 更改密码
    Jenkins启动报端口被占用,解决办法FAILED ServerConnector@2a265ea9{HTTP/1.1}{0.0.0.0:8080}: java
    ajax无法跳转页面的问题,
    EF查询性能优化相关
    code first从入门到伪精通
    自适应Bootstrap学习
    每月分享github上有意思的项目
  • 原文地址:https://www.cnblogs.com/drl937676516/p/3579298.html
Copyright © 2020-2023  润新知