欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java实现gif动画效果(java显示动态图片),javagif

来源: javaer 分享于  点击 2608 次 点评:100

java实现gif动画效果(java显示动态图片),javagif


关闭 关闭
  • 网页制作
  • 网络编程
  • 脚本专栏
  • 脚本下载
  • 数据库
  • CMS教程
  • 电子书籍
  • 平面设计
  • 媒体动画
  • 操作系统
  • 网站运营
  • 网络安全
  • 在线手册
  • C#教程
  • vb
  • vb.net
  • C 语言
  • Java编程
  • Delphi
  • java
  • Android
  • IOS
  • Swift
  • Scala
  • 易语言
  • 其它相关
您的位置:首页 → 软件编程 → java → 正文内容 java动态图片
  • 低价出售流量10000IP只需8元
  • DDos高防IP
  • 16核独服350/固态盘独服288/创梦网络
  • 美国云20元/香港云29元/韩国云55元
  • 装软件赚钱,每台电脑秒赚6.3元
  • 百兆 12核24线程 16G内存 2T 999/月
  • 微子网络 湛江双线高防 抗15G 700元起
  • 500家知名商城加盟,最高购物返利63%
  • 众生网络 基于云计算的互联网基础服务运营商
  • 服务器租用/托管-域名空间/认准腾佑科技
  • BGP四线 亿恩1U服务器托管3999元/年
  • 九九数据 — 工信部认可正规资质IDC接入商
  • 枫信科技-江苏双线10M保证-399/元
  • 四核15M独享服务器特价188元/月
  • 免备vps20/百独799/双线350/45互联
  • 脚本之家 云服务器、百独服务器托管
  • 鼎点网络百兆独享服务器仅需999元
  • 免备案国内虚拟主机-163cdn
  • 畅游网络 百独服务器 包跑满 998元
  • 服务器租用 199元起

java实现gif动画效果(java显示动态图片)

作者: 字体:[增加 减小] 类型:转载 时间:2014-04-29 我要评论

这篇文章主要介绍了java实现gif动画效果示例(java显示动态图片),需要的朋友可以参考下

就是每隔一定的时间显示一张图片,全部图片文件位于:“工作空间\项目名称\bin\动态图\花好月圆\”文件夹下。文件名类似:1001.jpg,1002.jpg,一直到1016.jpg:

复制代码 代码如下:
/*
 * Donttai.java
 *
 * Created on __DATE__, __TIME__
 */

package 动态图;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
 *
 * @author  __USER__
 */
public class Donttai extends javax.swing.JFrame implements Runnable
{

    /** Creates new form Donttai */
    public Donttai()
    {
        initComponents();
    }

    //String path = "E:\\Workspaces\\MyEclipse_9.0\\20120731\\bin\\动态图\\1\\10";
    //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
        {
            //g.drawImage(ImageIO.read(new File(Donttai.class.getResource("1.png").toString())), 20, 20, imageObserver);
            String temp = "";
            if (idx <= 9)
                temp = path + "0" + idx + ".jpg";
            else if (idx >= 10)
            {
                temp = path + idx + ".jpg";
            }
            g.drawImage(ImageIO.read(new File(temp)), 100, 50, 400, 300,
                    imageObserver);
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /** 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
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents()
    {

        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("jButton1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
                getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup()
                        .addContainerGap(483, Short.MAX_VALUE)
                        .addComponent(jButton1).addGap(35, 35, 35)));
        layout.setVerticalGroup(layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup().addGap(37, 37, 37)
                        .addComponent(jButton1)
                        .addContainerGap(392, Short.MAX_VALUE)));

        pack();
    }// </editor-fold>
    //GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        //        java.awt.EventQueue.invokeLater(new Runnable()
        //        {
        //            public void run()
        //            {
        //                new Donttai().setVisible(true);
        //               
        //            }
        //        });
        Donttai donttai = new Donttai();
        donttai.setVisible(true);
        donttai.run();
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton 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
            {
                Thread.sleep(60);
            }
            catch (InterruptedException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }

}关闭

java实现gif动画效果(java显示动态图片)

作者: 字体:[增加 减小] 类型:转载 时间:2014-04-29 我要评论

这篇文章主要介绍了java实现gif动画效果示例(java显示动态图片),需要的朋友可以参考下

就是每隔一定的时间显示一张图片,全部图片文件位于:“工作空间\项目名称\bin\动态图\花好月圆\”文件夹下。文件名类似:1001.jpg,1002.jpg,一直到1016.jpg:

复制代码 代码如下: /*
 * Donttai.java
 *
 * Created on __DATE__, __TIME__
 */

package 动态图;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
 *
 * @author  __USER__
 */
public class Donttai extends javax.swing.JFrame implements Runnable
{

    /** Creates new form Donttai */
    public Donttai()
    {
        initComponents();
    }

    //String path = "E:\\Workspaces\\MyEclipse_9.0\\20120731\\bin\\动态图\\1\\10";
    //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
        {
            //g.drawImage(ImageIO.read(new File(Donttai.class.getResource("1.png").toString())), 20, 20, imageObserver);
            String temp = "";
            if (idx <= 9)
                temp = path + "0" + idx + ".jpg";
            else if (idx >= 10)
            {
                temp = path + idx + ".jpg";
            }
            g.drawImage(ImageIO.read(new File(temp)), 100, 50, 400, 300,
                    imageObserver);
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /** 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
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents()
    {

        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("jButton1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
                getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup()
                        .addContainerGap(483, Short.MAX_VALUE)
                        .addComponent(jButton1).addGap(35, 35, 35)));
        layout.setVerticalGroup(layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup().addGap(37, 37, 37)
                        .addComponent(jButton1)
                        .addContainerGap(392, Short.MAX_VALUE)));

        pack();
    }// </editor-fold>
    //GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        //        java.awt.EventQueue.invokeLater(new Runnable()
        //        {
        //            public void run()
        //            {
        //                new Donttai().setVisible(true);
        //               
        //            }
        //        });
        Donttai donttai = new Donttai();
        donttai.setVisible(true);
        donttai.run();
    }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JButton 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
            {
                Thread.sleep(60);
            }
            catch (InterruptedException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }

}

相关文章

    暂无相关文章
相关栏目:

用户点评