首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

SWT学习札记3——颜色、字体、图片

2012-08-29 
SWT学习笔记3——颜色、字体、图片import org.eclipse.swt.graphics.Colorimport org.eclipse.swt.graphics.F

SWT学习笔记3——颜色、字体、图片




import org.eclipse.swt.graphics.Color;import org.eclipse.swt.graphics.Font;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.graphics.ImageData;import org.eclipse.swt.graphics.PaletteData;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.wb.swt.SWTResourceManager;import org.eclipse.swt.widgets.Button;public class TestColorImageFont {static Display display = Display.getDefault();//三种颜色获取方式static Color white = new Color(display, 255, 255, 255);static Color sysBlack = display.getSystemColor(SWT.COLOR_BLACK);static Color swtBlue = SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION);//两种图片获取方式,外加自己生成图片自己写数据static Image errorIcon = display.getSystemImage(SWT.ICON_ERROR); //内置图像static Image tigerIcon = new Image(display, "hu.jpg");//读取的图像//自己生成图像,参数为 图像宽、高,颜色的depth,RGB的掩膜(RGB对应的bit)static ImageData imageData=new ImageData(20, 20, 24, new PaletteData(0xFF0000, 0xFF00, 0xFF));static Image createdIcon=new Image(display, imageData);//难道是独立的?设置完数据重新生成才有效!!!否则是黑的而且直接设置图片的内容也不行!!!//字体static Font sysFont = display.getSystemFont();static Font songFont = new Font(display, "宋体", 22, SWT.NONE);public static void main(String[] args) {//设置生成的图像的内容for (int x = 0; x < imageData.width; x++) {for (int y = 0; y < imageData.height; y++) {imageData.setPixel(x, y, 0xFF00FF);//createdIcon.getImageData().setPixel(x, y, 0xFF00FF);//没用啊!!!}}createdIcon=new Image(display, imageData);//不加此行改了图片数据也无效啊!!!Shell shell = new Shell();shell.setSize(576, 226);shell.setText("SWT Application");shell.setBackground(sysBlack);shell.setImage(display.getSystemImage(SWT.ICON_WORKING));Label lblErr = new Label(shell, SWT.NONE);lblErr.setForeground(white);//前景颜色lblErr.setBackground(swtBlue);//背景颜色lblErr.setBounds(10, 10, 78, 32);//lblNewLabel.setImage(errorIcon); //label中文字和图片不能同时显示lblErr.setText("Error Label");lblErr.setToolTipText("label中文字和图片不能同时显示");Button btn = new Button(shell, SWT.NONE);btn.setAlignment(SWT.RIGHT);btn.setBounds(94, 31, 462, 127);btn.setText("Button Text");btn.setImage(tigerIcon);//图片btn.setFont(songFont);//字体Label lblCreate=new Label(shell, SWT.NONE);lblCreate.setAlignment(SWT.CENTER);lblCreate.setBounds(10, 100, 78, 32);lblCreate.setImage(createdIcon);shell.open();shell.layout();while (!shell.isDisposed()) {if (!display.readAndDispatch()) {display.sleep();}}}}

热点排行