SWTJface权威指南SWT中控件的使用.docx

上传人:b****5 文档编号:5341048 上传时间:2022-12-15 格式:DOCX 页数:19 大小:139.46KB
下载 相关 举报
SWTJface权威指南SWT中控件的使用.docx_第1页
第1页 / 共19页
SWTJface权威指南SWT中控件的使用.docx_第2页
第2页 / 共19页
SWTJface权威指南SWT中控件的使用.docx_第3页
第3页 / 共19页
SWTJface权威指南SWT中控件的使用.docx_第4页
第4页 / 共19页
SWTJface权威指南SWT中控件的使用.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

SWTJface权威指南SWT中控件的使用.docx

《SWTJface权威指南SWT中控件的使用.docx》由会员分享,可在线阅读,更多相关《SWTJface权威指南SWT中控件的使用.docx(19页珍藏版)》请在冰豆网上搜索。

SWTJface权威指南SWT中控件的使用.docx

SWTJface权威指南SWT中控件的使用

/**

 * 作 者 :

李天泉

 *工作地:

北京中关村软件园   

 */

import org.eclipse.swt.*;

import org.eclipse.swt.widgets.*;

import org.eclipse.swt.layout.*;

import org.eclipse.swt.graphics.*;

/**

 * 此类演示Labels控件的使用

 */

public class LabelExample {

  public static void main(String[] args) {

    Display display = new Display();

    Shell shell = new Shell();

    shell.setLayout(new GridLayout(1, false));

    // 创建一个label控件

    new Label(shell, SWT.NONE).setText("This is a plain label.");

    // 创建一个垂直的分割线

    new Label(shell, SWT.SEPARATOR);

    // 创建一个带有边框的Label控件

    new Label(shell, SWT.BORDER).setText("This is a label with a border.");

    // 创建一个水平的分割线

    Label separator = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR);

    separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // 创建一个带有图片的label控件

     Image image = new Image(display, "heihei.jpg");

    Label imageLabel = new Label(shell, SWT.NONE);

    imageLabel.setImage(image);

    shell.setText("順天科技--勤學博思製作");

    shell.open();

    while (!

shell.isDisposed()) {

      if (!

display.readAndDispatch()) {

        display.sleep();

      }

    }

    display.dispose();

  }

}

 勤学博思回复于:

2005-03-3020:

21:

55

import org.eclipse.swt.SWT;

import org.eclipse.swt.layout.*;

import org.eclipse.swt.widgets.*;

/**

 * 此类演示 Buttons控件

 */

public class ButtonExample {

  public static void main(String[] args) {

    Display display = new Display();

    Shell shell = new Shell(display);

    shell.setLayout(new GridLayout(3, true));

    // 创建三个按钮控件

    new Button(shell, SWT.PUSH).setText("Push 1");

    new Button(shell, SWT.PUSH).setText("Push 2");

    new Button(shell, SWT.PUSH).setText("Push 3");

    // 常见三个复选框控件

    new Button(shell, SWT.CHECK).setText("Checkbox 1");

    new Button(shell, SWT.CHECK).setText("Checkbox 2");

    new Button(shell, SWT.CHECK).setText("Checkbox 3");

    // 创建三个绳钉控件(有两种状态的控件,同复选框,仅外观不一样)

    new Button(shell, SWT.TOGGLE).setText("Toggle 1");

    new Button(shell, SWT.TOGGLE).setText("Toggle 2");

    new Button(shell, SWT.TOGGLE).setText("Toggle 3");

    // 创建三个单选框控件

    new Button(shell, SWT.RADIO).setText("Radio 1");

    new Button(shell, SWT.RADIO).setText("Radio 2");

    new Button(shell, SWT.RADIO).setText("Radio 3");

    // 创建三个平面按钮

    new Button(shell, SWT.FLAT).setText("Flat 1");

    new Button(shell, SWT.FLAT).setText("Flat 2");

    new Button(shell, SWT.FLAT).setText("Flat 3");

    // 创建三个箭头按钮

    new Button(shell, SWT.ARROW);

    new Button(shell, SWT.ARROW | SWT.LEFT);

    new Button(shell, SWT.ARROW | SWT.DOWN);

    shell.setText("順天科技--勤學博思製作");

    shell.pack();

    shell.open();

    while (!

shell.isDisposed()) {

      if (!

display.readAndDispatch()) {

        display.sleep();

      }

    }

    display.dispose();

  }

}

 勤学博思回复于:

2005-03-3020:

26:

34

import org.eclipse.swt.SWT;

import org.eclipse.swt.layout.*;

import org.eclipse.swt.widgets.*;

/**

 * 此类演示 text fields控件

 */

public class TextExample {

  public static void main(String[] args) {

    Display display = new Display();

    Shell shell = new Shell(display);

    shell.setLayout(new GridLayout(1, false));

    // 创建一个单行的text field控件

    new Text(shell, SWT.BORDER);

    // 创建一个文本右对齐的text field控件

    new Text(shell, SWT.RIGHT | SWT.BORDER);

    // 常见一个密码text field控件

    new Text(shell, SWT.PASSWORD | SWT.BORDER);

    // 创建一个只读的text field控件

    new Text(shell, SWT.READ_ONLY | SWT.BORDER).setText("Read Only");

    // 创建一个多行文本的text field控件

    Text t = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);

    t.setLayoutData(new GridData(GridData.FILL_BOTH));

    shell.setText("順天科技--勤學博思製作");

    shell.open();

    while (!

shell.isDisposed()) {

      if (!

display.readAndDispatch()) {

        display.sleep();

      }

    }

    display.dispose();

  }

}

 勤学博思回复于:

2005-03-3020:

31:

48

import org.eclipse.swt.SWT;

import org.eclipse.swt.layout.*;

import org.eclipse.swt.widgets.*;

/**

 * 此类演示 List控件

 */

public class ListExample {

  // 字符串数组用于列表

  private static final String[] ITEMS = { "Alpha", "Bravo", "Charlie", "Delta",

    "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima", "Mike",

    "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform",

    "Victor", "Whiskey", "X-Ray", "Yankee", "Zulu"

};

  public static void main(String[] args) {

    Display display = new Display();

    Shell shell = new Shell(display);

    shell.setLayout(new FillLayout());

    //创建一个单选的list控件

    List single = new List(shell, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);

    // 添加List元素(单个方式添加)

    for (int i = 0, n = ITEMS.length; i < n; i++) {

      single.add(ITEMS);

    }

    // 默认选择第四个项目

    single.select(4);

    // 创建一个多选 list控件

    List multi = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);

    // 一次添加所有元素

    multi.setItems(ITEMS);

    // 选择10-12区间元素

    multi.select(9, 11);

    shell.setText("順天科技--勤學博思製作");

    shell.open();

    while (!

shell.isDisposed()) {

      if (!

display.readAndDispatch()) {

        display.sleep();

      }

    }

    display.dispose();

  }

}

 勤学博思回复于:

2005-03-3020:

36:

30

import org.eclipse.swt.SWT;

import org.eclipse.swt.layout.*;

import org.eclipse.swt.widgets.*;

/**

 * 此类演示Combo控件

 */

public class ComboExample {

  // 字符串数组用于列表项目

  private static final String[] ITEMS = { "Alpha", "Bravo", "Charlie", "Delta",

    "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima", "Mike",

    "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform",

    "Victor", "Whiskey", "X-Ray", "Yankee", "Zulu"

  };

  public static void main(String[] args) {

    Display display = new Display();

    Shell shell = new Shell(display);

    shell.setLayout(new GridLayout(2, true));

    // 创建下拉Combo控件

    Combo combo = new Combo(shell, SWT.DROP_DOWN);

    combo.setItems(ITEMS);

    // 常见一个只读的 Combo控件

    Combo readOnly = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);

    readOnly.setItems(ITEMS);

    // 创建一个“单行”的Combo控件

    Combo simple = new Combo(shell, SWT.SIMPLE);

    simple.setItems(ITEMS);

    shell.setText("順天科技--勤學博思製作");

    shell.open();

    while (!

shell.isDisposed()) {

      if (!

display.readAndDispatch()) {

        display.sleep();

      }

    }

    display.dispose();

  }

}

 勤学博思回复于:

2005-03-3020:

39:

38

import org.eclipse.swt.SWT;

import org.eclipse.swt.layout.*;

import org.eclipse.swt.widgets.*;

/**

 * 此类演示Sliders控件

 */

public class SliderExample {

  public static void main(String[] args) {

    Display display = new Display();

    Shell shell = new Shell(display);

    shell.setLayout(new GridLayout(1, false));

    // 创建一个水平的Slider,默认情况下为水平

    new Slider(shell, SWT.HORIZONTAL);

    // 创建一个垂直的Slider控件,并设置相关属性

    Slider slider = new Slider(shell, SWT.VERTICAL);

    slider.setMinimum(0);

    slider.setMaximum(100);

    slider.setIncrement(5);

    slider.setPageIncrement(20);

    slider.setSelection(75);

    shell.setText("順天科技--勤學博思製作");

    shell.open();

    while (!

shell.isDisposed()) {

      if (!

display.readAndDispatch()) {

        display.sleep();

      }

    }

    display.dispose();

  }

}

 勤学博思回复于:

2005-03-3020:

42:

07

import org.eclipse.swt.SWT;

import org.eclipse.swt.layout.*;

import org.eclipse.swt.widgets.*;

/**

 * 此类演示Groups控件

 */

public class GroupExample {

  public static void main(String[] args) {

    Display display = new Display();

    Shell shell = new Shell(display);

    shell.setLayout(new GridLayout());

    //创建第一个Group(分组框)控件

    Group group1 = new Group(shell, SWT.SHADOW_IN);

    group1.setText("Who's your favorite?

");

    group1.setLayout(new RowLayout(SWT.VERTICAL));

    new Button(group1, SWT.RADIO).setText("John");

    new Button(group1, SWT.RADIO).setText("Paul");

    new Button(group1, SWT.RADIO).setText("George");

    new Button(group1, SWT.RADIO).setText("Ringo");

    // 创建第二个Group

    Group group2 = new Group(shell, SWT.NO_RADIO_GROUP);

    group2.setText("Who's your favorite?

");

    group2.setLayout(new RowLayout(SWT.VERTICAL));

    new Button(group2, SWT.RADIO).setText("Barry");

    new Button(group2, SWT.RADIO).setText("Robin");

    new Button(group2, SWT.RADIO).setText("Maurice");

    shell.setText("順天科技--勤學博思製作");

    shell.open();

    while (!

shell.isDisposed()) {

      if (!

display.readAndDispatch()) {

        display.sleep();

      }

    }

    display.dispose();

  }

}

 勤学博思回复于:

2005-03-3020:

45:

22

import org.eclipse.swt.SWT;

import org.eclipse.swt.layout.*;

import org.eclipse.swt.widgets.*;

/**

 * 此类演示ScrollBars控件

 */

public class ScrollBarExample {

  public static void main(String[] args) {

    Display display = new Display();

    Shell shell = new Shell(display);

    shell.setLayout(new FillLayout());

    //创建一个ScrollBar关联一个List

    List list = new List(shell, SWT.V_SCROLL);

    // 添加元素到List

    for (int i = 0; i < 500; i++) {

      list.add("A list item");

    }

    // 选择最后一个选项

    list.select(list.getItemCount() - 1);

    list.showSelection();

    // 取得ScrollBar

    ScrollBar sb = list.getVerticalBar();

    list.add("Selection:

 " + sb.getSelection());

    shell.setText("順天科技--勤學博思製作");

    shell.open();

    while (!

shell.isDisposed()) {

      if (!

display.readAndDispatch()) {

        display.sleep();

      }

    }

    display.dispose();

  }

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 艺术

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1