欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SWT(JFace)體驗(yàn)之圖片的動態(tài)漸變效果

 更新時間:2009年06月25日 12:05:57   作者:  
SWT(JFace)體驗(yàn)之圖片的動態(tài)漸變效果
1.漸變:
復(fù)制代碼 代碼如下:

package swt_jface.demo10;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class AlphaFadeIn {
    Display display = new Display();
    Shell shell = new Shell(display);
    public AlphaFadeIn() {

        shell.setLayout(new FillLayout());
        final Canvas canvas = new Canvas(shell, SWT.NULL);

        ImageData imageData = new ImageData("C:/icons/eclipse.jpg");
        byte[] alphaValues = new byte[imageData.height * imageData.width];
        for(int j=0; j<imageData.height; j++) {
            for(int i=0; i<imageData.width; i++) {
                alphaValues[j*imageData.width + i] = (byte) (255 - 255 * i / imageData.width);
            }
        }
        imageData.alphaData = alphaValues;

        final Image image = new Image(display, imageData);

        canvas.addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                e.gc.drawImage(image, 10, 10);
            }
        });
        shell.setSize(200, 100);
        shell.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }
    public static void main(String[] args) {
        new AlphaFadeIn();
    }
}

2.動態(tài)
復(fù)制代碼 代碼如下:

package swt_jface.demo10;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Animations {

    Display display = new Display();
    Shell shell = new Shell(display);
    public Animations() {

        shell.setLayout(new FillLayout());
        ImageLoader imageLoader = new ImageLoader();
        final ImageData[] imageDatas = imageLoader.load("C:/icons/eclipse-ani.gif");
        final Image image = new Image(display, imageDatas[0].width, imageDatas[0].height);
        final Canvas canvas = new Canvas(shell, SWT.NULL);
        canvas.addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                e.gc.drawImage(image, 0, 0);
            }
        });
        final GC gc = new GC(image);
        final Thread thread = new Thread() {
            int frameIndex = 0;
            public void run() {
                while (!isInterrupted()) {
                    frameIndex %= imageDatas.length;
                    final ImageData frameData = imageDatas[frameIndex];
                    display.asyncExec(new Runnable() {
                        public void run() {
                            Image frame =
                                new Image(display, frameData);
                            gc.drawImage(frame, frameData.x, frameData.y);
                            frame.dispose();
                            canvas.redraw();
                        }
                    });
                    try {
                        Thread.sleep(imageDatas[frameIndex].delayTime * 10);
                    } catch (InterruptedException e) {
                        return;
                    }
                    frameIndex += 1;
                }
            }
        };

        shell.addShellListener(new ShellAdapter() {
            public void shellClosed(ShellEvent e) {
                thread.interrupt();
            }
        });
        shell.setSize(400, 200);
        shell.open();

        thread.start();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }
    public static void main(String[] args) {
        new Animations();
    }
}

相關(guān)文章

  • spring注解 @Valid 的作用說明

    spring注解 @Valid 的作用說明

    這篇文章主要介紹了spring注解 @Valid 的作用說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • Java變態(tài)跳臺階實(shí)現(xiàn)思路和代碼

    Java變態(tài)跳臺階實(shí)現(xiàn)思路和代碼

    今天小編就為大家分享一篇關(guān)于Java變態(tài)跳臺階實(shí)現(xiàn)思路和代碼,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • Java實(shí)現(xiàn)石頭剪刀布游戲

    Java實(shí)現(xiàn)石頭剪刀布游戲

    這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)石頭剪刀布游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • 詳解Springboot事務(wù)管理

    詳解Springboot事務(wù)管理

    本篇文章主要介紹了詳解Springboot事務(wù)管理,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • 實(shí)例詳解java Struts2的配置與簡單案例

    實(shí)例詳解java Struts2的配置與簡單案例

    這篇文章主要介紹了java Struts2的配置與簡單案例,需要的朋友可以參考下
    2017-04-04
  • GSON實(shí)現(xiàn)Java對象與JSON格式對象相互轉(zhuǎn)換的完全教程

    GSON實(shí)現(xiàn)Java對象與JSON格式對象相互轉(zhuǎn)換的完全教程

    GSON是Google編寫并在在GitHub上開源的Java序列化與反序列化JSON的類庫,今天我們就來總結(jié)一下使用GSON實(shí)現(xiàn)Java對象與JSON格式對象相互轉(zhuǎn)換的完全教程
    2016-06-06
  • Java冒泡排序法和選擇排序法的實(shí)現(xiàn)

    Java冒泡排序法和選擇排序法的實(shí)現(xiàn)

    這篇文章主要介紹了Java冒泡排序法和選擇排序法的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • Springboot整合Gson報(bào)錯問題解決過程

    Springboot整合Gson報(bào)錯問題解決過程

    這篇文章主要介紹了Springboot整合Gson報(bào)錯問題解決過程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-06-06
  • websocket在springboot+vue中的使用教程

    websocket在springboot+vue中的使用教程

    這篇文章主要介紹了websocket在springboot+vue中的使用教程,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-08-08
  • Spring常用數(shù)據(jù)源的xml配置詳解

    Spring常用數(shù)據(jù)源的xml配置詳解

    這篇文章主要介紹了Spring常用數(shù)據(jù)源的xml配置詳解,數(shù)據(jù)源是連接到數(shù)據(jù)庫的一類路徑,它包含了訪問數(shù)據(jù)庫的信息(地址、用戶名、密碼),數(shù)據(jù)源就像是排水管道,需要的朋友可以參考下
    2023-07-07

最新評論