java实现gif动画效果代码参考

来源:才华咖  本文已影响2.95W人 

复制代码 代码如下:

java实现gif动画效果代码参考

/*

*

*

* Created on __DATE__, __TIME__

*/

package 动态图;

import hics;

import e;

import eObserver;

import ;

import ception;

import eIO;

/**

*

* @author __USER__

*/

public class Donttai extends me implements Runnable

{

/** Creates new form Donttai */

public Donttai()

{

initComponents();

}

//String path = "E:WorkspacesMyEclipse_9.020120731bin动态图110";

//Java默认文件路径项目的根目录,所以要手动加上bin及其以下的路径

String path="bin/动态图/花好月圆/10";

int idx = 1;

public void paint(Graphics g)

{

ImageObserver imageObserver = new ImageObserver()

{

@Override

public boolean imageUpdate(Image img, int infoflags, int x, int y,

int width, int height)

{

// TODO Auto-generated method stub

return false;

}

};

try

{

//Image((new File(Donttai.class.getResource("1.png")ring())), 20, 20, imageObserver);

String temp = "";

if (idx <= 9)

temp = path + "0" + idx + ".jpg";

else if (idx >= 10)

{

temp = path + idx + ".jpg";

}

Image((new File(temp)), 100, 50, 400, 300,

imageObserver);

}

catch (IOException e)

{

// TODO Auto-generated catch block

tStackTrace();

}

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

//GEN-BEGIN:initComponents

//

private void initComponents()

{

jButton1 = new ton();

setDefaultCloseOperation(_ON_CLOSE);

ext("jButton1");

pLayout layout = new pLayout(

getContentPane());

getContentPane()ayout(layout);

orizontalGroup(teParallelGroup(

ING)roup(

LING,

teSequentialGroup()

ontainerGap(483, _VALUE)

omponent(jButton1)ap(35, 35, 35)));

erticalGroup(teParallelGroup(

ING)roup(

teSequentialGroup()ap(37, 37, 37)

omponent(jButton1)

ontainerGap(392, _VALUE)));

pack();

}//

//GEN-END:initComponents

/**

* @param args the command line arguments

*/

public static void main(String args[])

{

// keLater(new Runnable()

// {

// public void run()

// {

// new Donttai()isible(true);

//

// }

// });

Donttai donttai = new Donttai();

isible(true);

();

}

//GEN-BEGIN:variables

// Variables declaration - do not modify

private ton jButton1;

// End of variables declaration//GEN-END:variables

@Override

public void run()

{

// TODO Auto-generated method stub

while (true)

{

repaint();

if (idx < 16)

idx++;

else

idx = 1;

try

{

p(60);

}

catch (InterruptedException e)

{

// TODO Auto-generated catch block

tStackTrace();

}

}

}

}

相关内容

热门精选